Ask Experts Questions for FREE Help !
Ask
    ugurmurat's Avatar
    ugurmurat Posts: 4, Reputation: 1
    New Member
     
    #1

    Nov 26, 2007, 07:38 AM
    vb6 if statement (i think?)
    Hi and Thanks for all replies

    Textbox1 0 - 36

    Textbox2 36 - 44

    Textbox3 44 - 68

    if the Textbox1 = 45 then

    automatically Textbox1 will change to 36 then

    Textbox2 will change to 8 and then

    Textbox3 will change to 1 so its all added to 45 again but in different Boxes

    this is not just for one number any number up to 68 will need to do the same thing

    if Textbox1 equaled to 36 then Textbox2 and Textbox3 will be empty

    hope I am clear

    Thankyou very much this will help me allot:)
    ugurmurat's Avatar
    ugurmurat Posts: 4, Reputation: 1
    New Member
     
    #2

    Nov 26, 2007, 02:56 PM
    if val(text1.text) > 36 then
    text2.text = val(text1.text) - 36
    if val(text2.text) > 44 then
    text3.text = val(text2.text) - 44
    text2.text = 44
    end if
    text1.text = 36
    elseif val(text1.text) = 36 then
    text2.text = ""
    text3.text = ""
    end if

    this kind a works but I am having trouble with text3

    if I input 45 to text1

    output is

    text1 = 36
    text2 = 9
    text3 = nothing at all!

    I want it so

    text1 = 36
    text2 = 8
    text3 = 1

    but this number is not static

    if I enter 34 I would only get two boxes that add up to 34 first box would have to be 36 then secound would be 4 makes 34 in total


    let me put it this way its bit more understandable


    Textbox1 1 - 36 -- so only 1 to 36 numbers can appear

    Textbox2 36 - 44 -- so only 1 to 8 numbers can appear

    Textbox3 44 - 68 --so only 1 - 24 numbers can appear


    Thanks :-)
    Duane in Japan's Avatar
    Duane in Japan Posts: 282, Reputation: 8
    Full Member
     
    #3

    Nov 30, 2007, 09:02 PM
    Since textbox2 can only show 1 ~ 8 then code in the keypress code of the number keys 1 ~ 8, if any higher number tries to get inserted then subtract 8 from the higher number and pass it on the textbox3.

    I will look around for this info, my explanation is no good I know.

    Your pseudo code is telling you what to do though. You just need to do some math.


    If val(text2.text) > 44 then

    Don't you want,

    If val(text2.text) > 8 then
    'do something else... not what you have
    Duane in Japan's Avatar
    Duane in Japan Posts: 282, Reputation: 8
    Full Member
     
    #4

    Nov 30, 2007, 09:52 PM
    Remember, your code runs from top to bottom (as a beginner), each row of code gets ran one line at a time.

    Pseudo Code,

    If text1 > 36 then
    text2 = text1 - 36
    text1 = 36
    elseif text1 < 36
    end sub 'no further need to run the rest of the code
    If text2 > 8 then
    text3 = text2 - 8
    text2 = 8
    elseif text2 < 8
    end sub 'no further need to run the rest of the code

    text2 and text3 will be left blank if needed, you can also code in to make these boxes 0 instead of blank if you like. It appears that you need the simplest code for a project, it can get more complicated though.

    Do you not have a text4 TOTAL box? How is each box getting focus, if needed, through the use of the Enter Key or the Tab Key or just let the code do all the work?

    http://download.microsoft.com/downlo...e2462/05vb.wmv

    Here is a video tutorial.

    and another set.

    How-To Windows Forms Controls Series – Visual Basic

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Crystal report with vb6 [ 1 Answers ]

I design a software with vb6, ms access 2000 and crystal report 8.5. but when I tried to make package through package & deployment wizards, it cannot make package and hangs. What's the problem? Anyone help me?

Simple convert in VB6 [ 1 Answers ]

I'm having a minor problem to convert hexadecimal (entered as string in a textbox) into decimal. Currently, I'm trying to do the conversion through ascii method... but seems unable to get the right syntax. Or are there any functions in VB6 that does this? Thanks everyone.


View more questions Search