Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Basic Visual Basic 6.0 Help  (Read 5970 times)

0 Members and 1 Guest are viewing this topic.

T-Chai

  • Guest
Basic Visual Basic 6.0 Help
« on: June 01, 2006, 06:22:59 AM »
Hi to you all Computer Expert
I need help in building a simple buy and sell game, what i am stuck on is to difficult but i know some of the guys in here are good at programming. So here it is:


1. I want to get the user to type something in a textbox which will be save as Integer and i want to use the variable for later calculation
What i did is this::

:exclamation
Module:
Public nUnit as String   ' nUnit need to be integer'

Private Sub Form1_activate()
nUnit = Textbox.Text
End Sub

but it only work as string only.

2. As all of the buy and sell games must have money, I am stuck on a problem with calculation so here it is:
I have an option button which i want it to be click and calculated with user input numbers and display the result.

Operation must goes like this:
The user click on an option button and the user type in the number in a text box.
Now the user must click a button to process the calculation. This what i do but is wrong:

Module:
Public money as Single
Public nUnit as interger

Private Sub Form1_activate()
money = 200
End Sub


Private Sub Buy_Click()
If Option1.Value = True Then
money = money - (caliorg * nUnit)
backpack.Caption = caliorg & " " & nUnit & "Unit"              #Note~ that caliorg is save Integer#
End If
End Sub
 :exclamation
This did not work but can you tell me who to fix it please.

3.Why this type of function can only work ones:

Module:
Public days as Integer

Private Sub Form1_Activate()
days = 0
End Sub

Private Sub Sleep_Click()
days = days + 1
label.Caption = "Day " & days    #Note~ this button only work once why  :question
End Sub                                  
I want it every time i clicked them it will update it every time so the number of days goes up  by one.

4.How do i refresh every thing in a form ?
5.How do i creat a random number in VB

I hope this will be a easy answer for you Expert
Thank You


« Last Edit: June 01, 2006, 06:29:08 AM by T-Chai »

T-Chai

  • Guest
Re: Basic Visual Basic 6.0 Help
« Reply #1 on: June 03, 2006, 05:14:07 PM »
I guess no one here is an expert in programming

uncontroled_teen



    Rookie
    Re: Basic Visual Basic 6.0 Help
    « Reply #2 on: June 03, 2006, 08:51:09 PM »
    wish i could help but im no good with basic

    T-Chai

    • Guest
    Re: Basic Visual Basic 6.0 Help
    « Reply #3 on: June 10, 2006, 05:59:11 AM »
    It seem that every body can post some easy question but instead of answering some other question and helping people and this is no expert advice at all. I respec Flame GX1_Man Robpeomeroy Dl65 Sidewinder Fed because they actually no something but every one els is nothing but helpless sometime and all they do is add up there post cont WFT.
    My question above I really need this to be answer because you cant fine it anywhere on the web
    One question member, do you know anybody that is actually good at programming?
    « Last Edit: June 10, 2006, 05:59:57 AM by T-Chai »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Basic Visual Basic 6.0 Help
    « Reply #4 on: June 10, 2006, 07:49:00 PM »
    1. Replace the textbox with a Masked Edit Control (Project==>Components==>Microsoft Masked Edit Control). You'll be able to force the user to enter numerics into the control; also set it's length. Not sure why you're using the Activate event to get input. Usually you define a button control and use the _click event. Be sure to change nUnit to an integer.

    2. By putting money= 200 in a subroutine you're creating a scope problem; code it inline in the module. caliorg is undefined...you may not have posted enough code.

    3. I can't make out from your code what you're trying to do but I think days only has scope within the subroutine and reverts back to zero after the subroutine ends. Try making days a global field.

    4. Not sure on this; you can always use the unload method on the form followed by the load method. Why would you need to do this? Forms are updated as the underlying data changes.

    5. Use the rand() function.

    Good luck.  8-)

    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    T-Chai

    • Guest
    Re: Basic Visual Basic 6.0 Help
    « Reply #5 on: June 11, 2006, 06:32:05 AM »
     ;D ;D ;D
    Thanks You alot
    I have a go at it i reply if i cant do something

    T-Chai

    • Guest
    Re: Basic Visual Basic 6.0 Help
    « Reply #6 on: June 11, 2006, 06:57:35 AM »
    Quote
    2. By putting money= 200 in a subroutine you're creating a scope problem; code it inline in the module. caliorg is undefined...you may not have posted enough code.
    i already have my money save as single money = 200 and i want to do a further calculation with it.

    Module:
    Public money as Single
    Public nUnit as interger

    Private Sub Form1_activate()
    money = 200
    caliorg = 25.50
    and nUnit is a number the user specify
    End Sub
     
     
    Private Sub Buy_Click()
    If Option1.Value = True Then
    money = money - (caliorg * nUnit)                                    
    backpack.Caption = caliorg & " " & nUnit & "Unit"              
    End If
    End Sub

    This it what i want to do but it doesnot work

    Quote
    3. I can't make out from your code what you're trying to do but I think days only has scope within the subroutine and reverts back to zero after the subroutine ends. Try making days a global field.
    I want to click on a button that will change its number by 1 every time i click on it. So what i mean is that every time i click the button it will add up the number of 1 everytime.

    Quote
    4. Not sure on this; you can always use the unload method on the form followed by the load method. Why would you need to do this? Forms are updated as the underlying data changes.
    True i dont really need this

    Quote
    5. Use the rand() function.
    How can i limit the number.
    Let say i want the number to by random between 10 - 30 and it go to be single so sometime the number will be 15.67 or 20.64 ect.
    « Last Edit: June 11, 2006, 08:48:25 AM by T-Chai »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Basic Visual Basic 6.0 Help
    « Reply #7 on: June 11, 2006, 09:34:13 AM »
    2 & 3: It's time to start debugging your code. Best way is to set a well placed breakpoint, run the job interactively and as soon as you hit the breakpoint, step into the code and see how the program runs and what values the fields take on. There seems to be some doubt that the _Activate event ever runs. The VB package has a very full and rich help function which should answer most of your questions.

    5:
    Code: [Select]
    Public Function Rand(ByVal Low As Long, _
                         ByVal High As Long) As Long
      Rand = Int((High - Low + 1) * Rnd) + Low
    End Function

    I mistyped RND as RAND in my earlier post. Sorry for the confusion. It might also be wise to execute a RANDOMIZE instruction in the FORM_LOAD event to seed the random number generator.

     8-)
    « Last Edit: June 11, 2006, 09:35:29 AM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    T-Chai

    • Guest
    Re: Basic Visual Basic 6.0 Help
    « Reply #8 on: June 11, 2006, 09:36:29 AM »
    You are a great help thankyou

    xilinx

    • Guest
    Re: Basic Visual Basic 6.0 Help
    « Reply #9 on: July 12, 2006, 10:01:45 PM »
    Quote
    2 & 3: It's time to start debugging your code. Best way is to set a well placed breakpoint, run the job interactively and as soon as you hit the breakpoint, step into the code and see how the program runs and what values the fields take on. There seems to be some doubt that the _Activate event ever runs. The VB package has a very full and rich help function which should answer most of your questions.

    5:
    Code: [Select]
    Public Function Rand(ByVal Low As Long, _
                         ByVal High As Long) As Long
      Rand = Int((High - Low + 1) * Rnd) + Low
    End Function

    I mistyped RND as RAND in my earlier post. Sorry for the confusion. It might also be wise to execute a RANDOMIZE instruction in the FORM_LOAD event to seed the random number generator.

     8-)

    I don't understand why you need to use this function?If you don't mind to explain it to me.Thanks. :)

    As I know in vb if you want to convert string to int you only to write this code. For example :

    Dim total As Integer
    total = CInt(txtTotal.text)

    same if you want to convert label. caption.

    Eg :
    Dim total As Integer
    total = CInt(lblTotal.Caption)

    or if you want to convert it to Double just write:

    Dim total as Double
    total = CDbl(lbltotal.Caption)

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Basic Visual Basic 6.0 Help
    « Reply #10 on: July 13, 2006, 05:40:32 AM »
    Which function are you talking about? The rand function was used as a teaching aid to show the original poster how to create random numbers. A function was used since by definition a function returns a result.

    If you're referring to the Int function, the integer portion of the result from the Rnd function is needed, so it was necessary to truncate the decimal portion. CInt would have rounded the result to the nearest even number. Fix could also have been used in this case. When dealing with VB functions, always read the fine print.
     
     8-)
     
    Note: using the .text and .caption properties in numeric conversions will crash and burn your program should they resolve to non-numeric strings.
    « Last Edit: July 13, 2006, 07:03:11 AM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein