CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Location
    Indiana USA
    Posts
    193

    Printing a variable in a label once a form reloads

    I have a form where the user enters a date in a text box. The date is held in a variable named PayEnding$. I have declared it public in a module. I have a label that is to print the date if the form is loaded again. I don't want it to print as the user is typing, only if the form is used again. Then if used a third time, I want the second date to show in the label. (Hope this makes since). Anyway, I can't get it to work. I have tested the PayEnding$, with labels on other forms, and the date is there, I just need help with the code to make the date label show the previous date entered and blank if no date was entered. Here is the code I currently have that doesn't work:
    Dim A as Variant
    Dim CurrDate as date
    Dim B as Integer
    If KeyAscii = 13 then
    KeyAscii = 0
    Zout$ = txtEnding.Text
    If PayEnding$ = "" then
    lblEnding.Visible = false
    else
    lblEnding.Visible = true
    lblEnding.Caption = mid$(PayEnding$, 1, 2) + "/" + mid$(PayEnding$, 3, 2) + "/" + mid$(PayEnding$, 7, 2)

    End If



    If Val(mid$(Zout$, 1, 2)) < 1 Or Val(mid$(Zout$, 1, 2)) > 12 then
    B = MsgBox("Invalid Month, Please enter again.")
    End If

    If Val(mid$(Zout$, 3, 2)) < 1 Or Val(mid$(Zout$, 3, 2)) > 31 then
    B = MsgBox("Invalid Day, Please enter again.")
    End If

    If Val(mid$(Zout$, 5, 4)) < Val(mid$(CurrDate, 7, 2) + 2000) - 2 Or Val(mid$(Zout$, 5, 4)) > Val(mid$(CurrDate, 7, 2) + 2000) + 2 then
    B = MsgBox("Invalid Year, Please enter again.")
    End If

    If B = 1 then
    lblEnding.Caption = ""
    txtEnding.Text = ""
    txtEnding.SetFocus
    Exit Sub
    End If

    A = MsgBox("This this date Correct?", vbYesNo, "PDP")

    If A = 7 then
    lblEnding.Caption = ""
    txtEnding.Text = ""
    txtEnding.SetFocus
    else
    txtCheck.SetFocus
    End If
    End If

    PayEnding$ = Zout$
    End Sub




    Thank you for any help.

    Catrina



  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Printing a variable in a label once a form reloads

    Why not just check this variable at form load? your Payending variable is global, right? so in form load, just set the label's caption to this value. if its the first time through - it will be blank, if its the second time, it will have the first time's value.

    hope this helps,

    John

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured