Nov 8, 2009

Visual Basic.NET Help Needed.

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > BASIC / Visual Basic (.NET)

Visual Basic.NET Help Needed.

dhanesh
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.

Click to view attachment

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.

Comment/Reply (w/o sign-up)

dhanesh
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.

 

 

 


Comment/Reply (w/o sign-up)

tansqrx
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

Comment/Reply (w/o sign-up)

dhanesh
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.

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
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..

Comment/Reply (w/o sign-up)

dhanesh
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 <<

Comment/Reply (w/o sign-up)

dhanesh
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.

Click to view attachment

Comment/Reply (w/o sign-up)

tansqrx
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.

Comment/Reply (w/o sign-up)

iGuest-Kathie
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

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : visual, basic, net, needed

  1. Suggestions Needed For Latest Ycc Bot Maker Breakdown
    (5)
  2. Necklace Problem In Visual Basic
    (3)
    I was wondering if anyone could write code for this program. Its the usual Necklace Problem I'll
    give you the problem. A Necklace is a collection of numbers that begins with two single digit
    integers, the next number is obtained by adding the first two digits together and saving only the
    ones digit. This process is repeated until the 'necklace' closes by returning to the
    original two numbers. I think it is a Do While Loop but i am not sure. Thankyou....
  3. Delete A Registry Subkey And Key
    Using Visual Basic 2005 Express (8)
    Hi, does anyone know how to delete a registry key/subkey using VB 2005 Express. Also, if any other
    methods using VB, C#, C++, J#, post them as well.....
  4. Visual Basic Projects: Scoreboard
    Making a scoreboard with Visual Basic 6 (0)
    Hi again, I've done another visual basic tutorial in this forum on how to make a simple,
    customized web browser. Now I am going to say how to make a scoreboard. To do so, open a Standard
    EXE project in Visual Basic 6.0 and insert 6 labels and 2 command buttons. Change the captions on
    these to: Label1: SCOREBOARD Label2: LIONS Label3: SWANS Label4: 0 Label5: 0 Label6: Waiting for
    update... Command1: TOUCHDOWN Command2: TOUCHDOWN Once you are done, it shoud look like this.
    Press F5 now to see it in action. It won't do anything, seeing as how there is no path ....
  5. Installed Internet Explorer 7?, Visual Basic Now Broken?
    (3)
    This quick guide shows you how to fix this error. Step 1): Go to your control list by right
    clicking the toolbar underneat the default controls and clicking "Components" or by Pressing "CTRL +
    T". Step 2): In the Components Box that pops up scroll down to "Microsoft Internet Controls",
    click on it once so that it becomes highlighted. Now look at its "Location" it will say either
    "C:\Windows\System32\ieframe.dll" or "C:\Windows\System32\ieframe.dll\1". Step 3): Now you need to
    browse for the correct file, so with the "Microsoft Internet Control" still highlighted cli....
  6. [help] Visual Studio .net 2005 Questions
    (8)
    Heya folks, i am back again with my annoying questions /wink.gif" style="vertical-align:middle"
    emoid=";)" border="0" alt="wink.gif" /> I have this project to submit by the 7th of may and i am
    really desperate for some help here. I will put my questions in numbers so it would be easy for you
    to solve them without confusion. 1) Earlier in a post i had asked if i could create Vista
    compatible applications in VB .NET 2005. Well i got a good response and i went ahead and installed
    the needful, but i still think something is wrong. Not that i know alot of whats going on aro....
  7. Visual Basic Express Tutorials
    Need resources (5)
    I have just downloaded Microsoft Visual Basic Express 2005 and I need a tutorial to help me learn
    how to create simple programs. I have already watched the 16 hour RSS Reader series from Microsoft
    and I'm currently working on that. I also have developed a Web Browser and a weather tracker
    system, from the help of Microsoft E-Books and other Microsoft resources. If you could find any
    non-Microsoft resource on Visual Basic Express, that would be greatly appreciated.....
  8. Is There A Free IDE For VB.NET Programming?
    Needing info on a free VB.net IDE if avaliable (4)
    I know that VB.net is proprietry to Microsoft /sad.gif" style="vertical-align:middle" emoid=":("
    border="0" alt="sad.gif" /> but is there a free IDE that has all the support that VB.NET has? I
    found one before but it just didnt support many of the things that VB.NET does such as timers which
    was really annoying. Does anyone know of any IDEs like this that support the same functions and
    features as VB.NET but without the rather hefty (Over priced, in my opinion) price tag? If anyone
    does then drop me a PM or a reply! Thanks....
  9. New Features In Visual Studio 2005 Windows Forms
    (1)
    i dunno if all of u are by now well versed with the new exciting features in visual studio 2005
    forms, but for me this article was enlightening. for the benifit of others who wre in the dark like
    me.... New Features in Visual Studio 2005 Windows Forms QUOTE The little voice in my head
    shouted "Don't do it! Don't do it!" as I contemplated using the worn out cliché "Good things
    come to those who wait" to describe the experience of designing Windows applications with Visual
    Studio 2005. However, that cliché accurately communicates the idea that building Wi....
  10. Visual Basic Names
    Visual Basic Variabe Names (11)
    In Visual Basic, what is the difference between: ResourceName ResourceName$ ResourceName& ....
  11. Direct-X And VB.NET - Help Needed.
    Any resouces? (1)
    I'm going to build up a 3D app, but have no experience in this (sound funny?). I'm going to
    use DirectX framework. I'm looking for a book (an ebook is better), or some kind of document to
    begin. Is there any tools for manage the code in VB.NET for DirectX? Can I use DirectX lib for
    VB.NET.....
  12. Visual Basic 6 + Crystal Reports 9
    how to distribute (8)
    I have made a software with Visual Basic 6 and Crystal Reprots 9. Now I have to distribute it on the
    client side but the problem is coming in distributing the Crystal Reports. I have tried Setup
    Factory but it is not working. Then I have used Visual Studio Installer from Microsoft and
    downloaded Crystal Report Merge Modules from Business Objects website. It is working properly but
    now the setup file size is very big because it carries a lot of files with it. Is there any other
    installer software which can automatically select the required files to be distribute with the ....
  13. Visual Basic: Random Strings!
    (11)
    This article will teach you how to get random strings for output to a label caption, or anywhere you
    want it to go. 1. First we need to declare our string names: CODE Private RndString(2)
    This declaration says there will be an array of strings called RndString, and there will be 2
    strings in that array. 2. Then, we need to create a function that will generate a random number.
    CODE Private Function RandomNumber(rUpper As Integer, Optional rLower As Integer) As Integer
    ' Generate random number between upper and lower bound values    Randomize    R....
  14. Visual Basic: Change Your Start Button Text! (XP)
    Windows XP ONLY (17)
    Personally, I love this program I made for myself. What the following code will allow you to do is
    change the text of your start button (Duh). You can make it whatever you want, your name, a hobby,
    or even do some extra programming and get it to randomly cycle through captions every 30 seconds or
    so /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. Here is all
    the code you'll need: CODE Private Const WM_SETTEXT = &HC Private Const WM_GETTEXT = &HD
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpC....
  15. Visual Basic: Unload Your Application Correctly!
    (1)
    What many of us do not know is that using a button on a form with the function "Unload Form1" or
    even clicking the X in the upper right corner is like pulling the plug out of your computer while it
    is still on. It may not exit the program cleanly and efficiently, may leave background processes
    running, or just give you unwanted errors by exiting improperly. All you need to do is unload all
    components, forms, controls, etc. upon unloading. Say you have 2 forms in your project, 1
    component, and 2 controls. If these ojects are placed onto a form, unload them properly!....
  16. Visual Basic: Replace Explained!
    (6)
    This tutorial will go over how to effectively use the Replace function in Visual Basic. 1. So
    you have a string. Whether it be a label caption, an entry in a text box by the user of your
    program, or an item in a combo box. Let's say this is a bad string, something you do not want
    to appear. For instance, a user types "X is gay" in a text box, and you want to change that to
    something else. You can simply have it be deleted, or replaced with another value. 2. To make
    this work when a user types something in a textbox, you will need to use this sub: CODE ....
  17. Visual Basic.NET Through Movies
    (0)
    Hi all,     I found a very good site at MS which offers 101 short movie clips to strenghten various
    aspects of VB Programming and the IDE. Drastically cuts down on the learning curve. A very useful
    site for beginners: QUOTE Welcome to VB at the Movies. The 101 short films below will provide
    everybody from the beginner through the advanced developer with an opportunity to amp up their
    Visual Basic skills. Grab your popcorn and soda, sit back and enjoy! Source:
    http://msdn.microsoft.com/vbasic/atthemovies/default.aspx If you missed the link above, here it
    is a....
  18. Visual Basic Help
    need help useing visual basic (8)
    i was just wondering, when you are useing the program Visual Basic is there any way to add some
    animation to a form, and if so what is a good(cheep) animation program i could get?....
  19. [visual Basic] How To Confirm A Array Is Null
    (6)
    for example, Dim array() as integer during run time, how to confirm a array is null (do not
    contain any element) Thanks....
  20. Help Needed In VB.NET
    Video Player (1)
    Can someone help me in coding a video player in VB.net I have a button in my form . When i click it
    a new form will load which is a video player. It should play .avi files. I cant really get those
    codes... Thanks.......
  21. Visual Basic - make Standard dlls in VB
    written entierly by me (1)
    if you want to know how to make dlls in visual basic, download my submission to
    planet-source-code.com: http://www.planet-source-code.com/vb/scrip...=54190&lngWId=1 Quoting
    what i said on the submission: QUOTE This code will allow you to make your very own stdcall DLL
    files using Visual Basic. The DLLs that you create can be called from any programming language that
    supports stdcall DLLs. Just create or open a project with the functions that you want to export,
    choose the functions to export and click compile! Create your own DLLs that you can call from any
    pro....

    1. Looking for visual, basic, net, needed

See Also,

*SIMILAR VIDEOS*
Searching Video's for visual, basic, net, needed
advertisement



Visual Basic.NET Help Needed.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com