Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Visual Basic.NET Help Needed.
dhanesh
post Mar 26 2006, 05:41 PM
Post #1


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



I have a project to submit this wednesday, and i have to make it a working program. Not a big one .. but just sumthing small that includes : Splitter, Progress Bar & Track Bar.

I thought of making sumthing like the picture below, I would enter the text and hit the button .. the text would come in BOTH the labels. Then i move the track bar on the left to increase the font or/and the track bar on the right to change the color ( RBG only 3 colors ). The progress bar at the bottom will show the progress every time i move either of the track bars to a level.



Nothing fancy .. but just to see how it works, now i managed till changing color part, but i cant tend to program the "change font size" track bar and the progress bar ..

Another idea to make it easier .. was to put just 1 label insted of 2 .. so that when i hit the button, the text comes in the label and then when i more either of the track bars (color or font size ) the change appears in the label itself.

Regards
Dhanesh.

This post has been edited by dhanesh: Mar 26 2006, 05:42 PM
Attached File(s)
Attached File  1.JPG ( 12.27k ) Number of downloads: 146
 
Go to the top of the page
 
+Quote Post
dhanesh
post Mar 28 2006, 01:50 AM
Post #2


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



Okeyz , well i managed to do almost everything of it .. but m stuck on the progress bar sad.gif ..

Situation : I have a "Track Bar" to select either of the three colors (Red, Blue, Green), i select the color and hit a "button" wherein the colored text in l1 goes to l2,

Code for the "button"
If tbar.Value = 1 Then
l2.Text = l.Text
l2.ForeColor = Color.Green
pb.Value = 30
ElseIf tbar.Value = 2 Then
l2.Text = l.Text
l2.ForeColor = Color.Red
pb.Value = 60
............
............ etc
ElseIf tbar.Value = 0 Then
pb.Value = 0
End If

pb = progress bar , tbar = trackbar

What i want is when i select the color on the track bar and hit the button, i need the progress bar to run to 100% in say 1 min, not that anything is actually happening, but i need the progress bar to reach 100% and back to 0 (blank) in a span of 1 min. Is this possible. In the above code, when i select the color and hit the button, the progress bar just comes to 20 or 60 or 100 etc and stops there, i want it to go back to 0.

As far as i can guess, u need to initialize it to 0 ? but how ? i tried defining "A" as integer in global and after:

ElseIf tbar.Value = 2 Then
l2.Text = l.Text
l2.ForeColor = Color.Red
pb.Value = 60
pb.val = 0
..............etc

This is stupid lol and dosent work , but i kinda have no idea how to set a time out or counter or initialize .. whatever we can call it ..

Regards
Dhanesh.
Go to the top of the page
 
+Quote Post
tansqrx
post Mar 28 2006, 03:47 AM
Post #3


Super Member
Group Icon

Group: [HOSTED]
Posts: 557
Joined: 25-April 05
Member No.: 4,374
myCENTs:17.04



Been awhile since I have had to do some programming homework but here is a shot. I didn’t have the original problem so I tried to interpret your question as closely as possible. You apparently figured out most of the problem but was left with questions on the progress bar and font size which my example addresses. Please forgive me for not correctly naming all the variables, I threw this together in 20 minutes or so.

The key to VB.NET is to realize that most of it is event driven, For example, when you click a button then a button.clicked event is fired. For the color part I added a button, progress bar, and slider in the designer. I set the slider to minimum of 1 and maximum of 3, representing red, blue, and green. Now to get the progress bar to go up and down I also added a timer and set the interval to 50 ms. When you click the button, a global variable is set with the color and the timer is started. Every 50ms the timer will fire. Another global variable is used to keep track of the progress bar progress.

The timer function is split into four parts. The top half handles the progress bar going up and the bottom half handles the progress bar going down. Within each half, one section handles the increment/deincrement and the other half handles the boundary condition.

Changin the font is simpler still. Make a function that will handle the slider change event and set the label value to the slider value. I have to admit that I had to look up the font declaration on Google though.

I hope this helps. If you still have time and need help, let me know. The project can be found at http://www.ycoderscookbook.com/Files/ColorFontEx.rar

CODE
Option Strict On
Option Explicit On

Public Class Form1

    Private _iTimer As Integer
    Private _bDirection As Boolean
    Private _Color As System.Drawing.Color

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        'choose the color based on the slider value
        Select Case tbColor.Value
            Case 1
                _Color = Color.Red
            Case 2
                _Color = Color.Blue
            Case 3
                _Color = Color.Green
        End Select
        'start the timer for the progress bar
        Timer1.Start()
        'disable the button so they can't change the color before time is up
        btnStart.Enabled = False
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'start upward
        If _bDirection = False Then
            'move the pb one
            If _iTimer < 100 Then
                pbChange.Value = _iTimer
                _iTimer += 1
                'pb is at the top, change directions
            Else
                _bDirection = True
            End If
            'go back down
        Else
            'move pb down one
            If _iTimer > 0 Then
                pbChange.Value = _iTimer
                _iTimer -= 1
                'done
            Else
                Timer1.Stop()
                'reset everything so they can do it again
                pbChange.Value = 0
                _bDirection = False
                lChangeText.ForeColor = _Color
                'enable the button
                btnStart.Enabled = True
            End If
        End If
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        lChangeText.Font = New Font("Microsoft Sans Serif", TrackBar1.Value, FontStyle.Regular, GraphicsUnit.Point)
    End Sub
End Class
Go to the top of the page
 
+Quote Post
dhanesh
post Mar 28 2006, 05:49 AM
Post #4


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



Wooho .. finally. Thankx tansqrx for the help. Just a few more questions about the code you wrote tho smile.gif

If m not wrong, this is written in VB .NET 2005 ? I use 2003 .. I hope there will be no syntax change between the two. Because VB 6 to VB 2003 has syntax change.

Secondly, could you please explain what these lines do :
Option Strict On
Option Explicit On
---> what do these lines do ?

Private _bDirection As Boolean ----> isnt it supposed to be like Dim _bDirection As Boolean ? Y the Private ?

_bDirection
_iTimer
_Color
---> cant i just write direction, timer, color ? does the "_i" , "_b" or "_" mean anything important ?

Timer1_Tick ---> this is the timer control that i have to drag and drop in the form and then double click to code it .. right ?

lChangeText ----> this is the label name where the text will be changed ? like color and size ?

tbColor ---> this is the name for the color change track bar ?

I am a total starter at VB, and we have just been taught to make programs like "Add 2 numbers" , "Calculate the Profit based on values" etc .. basically the real beginners programs, so i have no idea about high level syntax.

Moving on to control working:

Font Change:
lChangeText.Font = New Font("Microsoft Sans Serif", TrackBar1.Value, FontStyle.Regular, GraphicsUnit.Point)
The above line will ONLY change the font size ? or will it change the font style ?

Progress bar:
The progress bar example that you provided is a little longer, takes almost 20sec to go up and 20 secs to go down .. how and where do i reduce this time taken. Also if the up time is 20 sec ... could the down time be 1 sec ? as in progress should go to 100% and then just vanish insted of goin down.

I am at office right now, and i cant think of anything more right now, your program was just too specific and to the point lol .. just like i wanted .. I will be leaving for college in 4 hrs and will go and try this there and will post up if i have more question. Hope i explained myself correctly, i am bad at explaining things sad.gif .. if you have any questions .. i'll be willing to illustrate too. Thankx again.

Regards
Dhanesh.

This post has been edited by dhanesh: Mar 28 2006, 05:51 AM
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Mar 28 2006, 06:09 AM
Post #5


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411
myCENTs:84.36



QUOTE(dhanesh @ Mar 28 2006, 12:49 PM) *

Wooho .. finally. Thankx tansqrx for the help. Just a few more questions about the code you wrote tho smile.gif

If m not wrong, this is written in VB .NET 2005 ? I use 2003 .. I hope there will be no syntax change between the two. Because VB 6 to VB 2003 has syntax change.


Nope - whatever syntax change was to happen has already happened between VB6 and VB.NET 2003. The whole coding paradigm was upgraded. Now you'll see only very minor changes - but no major leap.

QUOTE

Secondly, could you please explain what these lines do :
Option Strict On
Option Explicit On
---> what do these lines do ?

With Option Explicit set to On, you'll to explicitly define every variable before you use them (similar to C++). VB6 allowed you to simply use any random variable at any point of the code - which could add to massive confusion later on. This way you have to clearly outline your variables before you start coding and also minimizes the chance of naming clashes and subsequent overwriting of the same variable within scope.

Option Strict disallows you to cast between data types without proper casting commands. For example, you in VB6 you could equate an Integer var to a Float or String or whatever. Not so with Option Strict on. You've to use some data casting command - like System.Convert, CInt, CDouble etc. to change your data to a suitable type before assinging to a variable.

QUOTE

Private _bDirection As Boolean ----> isnt it supposed to be like Dim _bDirection As Boolean ? Y the Private ?

Almost same - but using simply Dim makes your variable Public by default. You've to read a bit more on the access modifiers. With the advent of OOP, now there are several access modifiers like Public, Private, Protected, Friend etc - each of which have a definite effect on the scope of the variable.

QUOTE

_bDirection
_iTimer
_Color
---> cant i just write direction, timer, color ? does the "_i" , "_b" or "_" mean anything important ?

The _i, _b is a clever trick that helps you avoid a lot of confusion later on. Normally you've no way of knowing WHAT DATA TYPE is a particular variable by looking at the code - unless you go back and refer to the variable declaration part. This task becomes very tiresome as your code increases. If you prefix your variables with a _i, _b, _f etc - you immediately know the type of your var,
i standing for Integer
b for Boolean
f for Float.. etc.. Just use your imagination.

Also certain words like Timer, Color etc - are either reserved keywords or name of some system constant. If you use variable names like these there might be clashes and problems... Thus it's an ideal coding practise to append a "_" (underscore) before the name of the variable. That also tells you that the name is question IS a variable defined by you.

QUOTE

Timer1_Tick ---> this is the timer control that i have to drag and drop in the form and then double click to code it .. right ?


Yep - right on. Also from the two drop-down boxes above the designer, you can PICK which event you want to code for and not just rely on the double-click to bring up the default event.

For the rest - over to tansgrx biggrin.gif Me got to get busy with work again smile.gif Good luck..
Go to the top of the page
 
+Quote Post
dhanesh
post Mar 29 2006, 01:54 AM
Post #6


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



Nice Explaination m^e .. thankx. But again like always i will annoy you with more questions tongue.gif , m leaving for office now, so will go to office and post from there.

In the mean time, i completed the program biggrin.gif !! yeayeee ! ... lol .. check the link and teme how it is .. i'll make minor changes if any .. b4 i submit it today ... A big Thanks again to you guys for helping out .. smile.gif

Regards
Dhanesh.

>> Download <<
Go to the top of the page
 
+Quote Post
dhanesh
post Mar 30 2006, 04:29 PM
Post #7


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



Finally its over smile.gif .. thanks for all ur help guys .. this is the final Program m attaching, its small and really n00bish tongue.gif .. but its my start .. atleast having a place like astahost to clear doubts would make me a successful programmer one day wink.gif .. thankx

Regards,
Dhanesh.



Attached File(s)
Attached File  Assignment_1__Size___Color__.zip ( 14.65k ) Number of downloads: 67
 
Go to the top of the page
 
+Quote Post
tansqrx
post Apr 3 2006, 06:49 PM
Post #8


Super Member
Group Icon

Group: [HOSTED]
Posts: 557
Joined: 25-April 05
Member No.: 4,374
myCENTs:17.04



I will try to answer all your questions. When you start out everything is a question and it is always good to find someone that will help you out.

QUOTE
If m not wrong, this is written in VB .NET 2005 ? I use 2003 .. I hope there will be no syntax change between the two. Because VB 6 to VB 2003 has syntax change.


There is no syntax change between 2003 and 2005, if there is it is an addition. VB.NET is an entirely new language from VB 6. One of the strongest similarities is the name. Outside of that, most everything has changed. The biggest difference in 2003 to 2005 is 2005 uses .NET Framework 2.0 opposed to .NET 1.1. .NET 2.0 adds new classes and methods to the framework. Any new changes can be seen in any of the .NET languages, even C#.

QUOTE
Secondly, could you please explain what these lines do :
Option Strict On
Option Explicit On
---> what do these lines do ?


This is just plain good programming practice. VB has a nasty habit of automatically converting data types when needed. Say you wanted to print the integer 4. Option Strict will not allow the complier to assume that the integer should automatically be converted to a string. Instead you will have to retype it similar to cstr(integer). This might look like a hassle at first but as your project grows you will get bit by this little “bug.” More complex data types so not convert as expected and you will spend hours if not day trying to figure out the problem. Option Explicit makes sure you declare each variable with a Dim. Same as above, you do not have to declare what type a variable is. VB will assume a conversion for you, even if it is wrong. In short I have been programming long enough that putting both options to on is the first thing I do in a project.

QUOTE
Private _bDirection As Boolean ----> isnt it supposed to be like Dim _bDirection As Boolean ? Y the Private ?


_bDirection is a global variable. As such I do not want it to be public outside the current class. Using Dim has an implied public attribute.

QUOTE
cant i just write direction, timer, color ? does the "_i" , "_b" or "_" mean anything important ?


Yes you can write anything you want. Where I work we follow a particular code standard. Its actually interesting because out standard goes against the Microsoft coding standard. The standard you see is commonly referred to Hungarian Notation. The first part of the variable represents what the variable is; i=integer, str=string, txt=textbox. The second part is the description with each word capitalized. From earlier you noticed the _ before the direction variable. This is another aspect of the coding standard. Global variable should have a _ before them. Practically this is used so you can have a property by the same name without the underscore. Also you will notice the b in front of Direction, which means it’s a Boolean variable.

QUOTE
Timer1_Tick ---> this is the timer control that i have to drag and drop in the form and then double click to code it .. right ?


Yes, just remember that double clicking only prompts for that control’s default action. In the case of a timer that is the tick event. In many cases there are many event you can capture from a control.

QUOTE
lChangeText ----> this is the label name where the text will be changed ? like color and size ?


Yes

QUOTE
tbColor ---> this is the name for the color change track bar ?


Yes

QUOTE
Font Change:
lChangeText.Font = New Font("Microsoft Sans Serif", TrackBar1.Value, FontStyle.Regular, GraphicsUnit.Point)
The above line will ONLY change the font size ? or will it change the font style ?


You can also change the style. You will have to make a variable out of the “Microsoft Sans Serif” field.

QUOTE
Progress bar:
The progress bar example that you provided is a little longer, takes almost 20sec to go up and 20 secs to go down .. how and where do i reduce this time taken. Also if the up time is 20 sec ... could the down time be 1 sec ? as in progress should go to 100% and then just vanish insted of goin down.


This is where your timer_tick event comes in. What happens is that every 50 ms the tick event fires and increments the counter by 1. You can change the timer.interval value to a smaller number or you could increment by a larger number i.e. iIndex+=2 to make it speed up. Changing to a different increment in either direction would change the up and down times. If you want the progress bar to clear after it gets to 100% then completely take the down part out and when iIndex gets to 100, stop the timer and set the progress bar value to 0.
Go to the top of the page
 
+Quote Post
iGuest
post Sep 10 2008, 02:25 PM
Post #9


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



flash or powerpoint info for vb2005
Visual Basic.NET Help Needed.

I am using vb2005, no big deal however I would like to upload either a flash8 show of photographs or a powerpoint but can't work out how to do that any help would be great.

-question by Kathie
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [visual Basic] How To Confirm A Array Is Null(6)
  2. Visual Basic Help(7)
  3. Visual Basic.NET Through Movies(0)
  4. Visual Basic: Replace Explained!(4)
  5. Visual Basic: Unload Your Application Correctly!(1)
  6. Visual Basic: Change Your Start Button Text! (XP)(16)
  7. Visual Basic: Random Strings!(10)
  8. Visual Basic 6 + Crystal Reports 9(6)
  9. Direct-X And VB.NET - Help Needed.(1)
  10. Visual Basic Names(11)
  11. New Features In Visual Studio 2005 Windows Forms(1)
  12. Is There A Free IDE For VB.NET Programming?(4)
  13. Visual Basic Express Tutorials(5)
  14. [help] Visual Studio .net 2005 Questions(8)
  15. Installed Internet Explorer 7?, Visual Basic Now Broken?(3)
  1. Visual Basic Projects: Scoreboard(0)
  2. Delete A Registry Subkey And Key(8)
  3. Necklace Problem In Visual Basic(3)
  4. Suggestions Needed For Latest Ycc Bot Maker Breakdown(5)


 



- Lo-Fi Version Time is now: