Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Vb6 if statement (I think?) (https://www.askmehelpdesk.com/showthread.php?t=156086)

  • Nov 26, 2007, 07:38 AM
    ugurmurat
    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:)
  • Nov 26, 2007, 02:56 PM
    ugurmurat
    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 :-)
  • Nov 30, 2007, 09:02 PM
    Duane in Japan
    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
  • Nov 30, 2007, 09:52 PM
    Duane in Japan
    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

  • All times are GMT -7. The time now is 06:23 AM.