Results 1 to 10 of 10

Thread: Simple Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Simple Question

    I'm kind of new in Visual Basic but done a macros for some time. Ok so here is my problem. I have this code, it is a small code, basically what I want is if then number is below 133000 a message box to show the msg, after the box i clicked on the code will start from the top.
    If this is not the place for questions like this can someone point me to where I shall post questions

    If strT > 1000000 Then
    strTseries = strTruckseq / 10

    ElseIf strTseries < 133000 Then
    MessageBox.Show("INVALID NUMBER")
    TextBox1.Clear()
    Button1_Click(sender, e)

    Thanks

  2. #2
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Simple Question

    What are your data types? Is strT an Integer or a String?

    You need to end your If statement as well. Where are you getting the values for strTseries and strTruckseq?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Re: Simple Question

    Thanks for reply all those vars are strings, I have no problem with that part the only part I have a problem is that when a invalid number is entered the message box appears, but when I press OK to enter the number again (textbox) the msgbox does not go away so I can run the code from the beginning automatically.

  4. #4
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Simple Question

    Big difference between VB.NET and macros: you need to use data types that fit the function. If you are comparing strings to numbers then you need to convert those strings to the equivalent data type.

    As for your message, I am having a very hard time understanding what you mean. Can you explain a little better?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Re: Simple Question

    Yes there is a BIG difference between the two. OK let me explain show what I have

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim strNum As String
    Dim strTr As String
    Dim strTrseq As String
    Dim strTseries As String
    Dim strPath As String
    Dim strFolder As String




    If strTseries > 1000000 Then
    strTseries = strTrseq / 10

    ElseIf strTseries < 133000 Then
    MessageBox.Show("INVALID NUMBER") 'here if the number is not valid i will like this msg to appear( which it does) then only problem is that it does not go away when ok pressed
    TextBox1.Clear() 'this will clear the textbox
    Button1_Clicksender, e) ' this I think starts the code from the beginning. here is the problem it get to this part of the code and the msgbox does not turn of or hide or close(dont know the term in VBA)

    ElseIf strTseries = "" Then
    MessageBox.Show("NO NUMBER ENTERED")
    TextBox1.Clear()

    End If


    strPath = "M:\demo\demo\" & strTseries & "\" & strNum & "\demo\demol"

    If Len(Dir(strPath, vbDirectory)) = 0 Then
    MessageBox.Show("No Folder Found")

    strFolder = "M:\bid_so\so\" & strTseries & ""


    Exit Sub
    End If

    strFolder = ""M:\demo\demo\" & strTseries & "\" & strNum & "\demo\demol""
    Shell("C:\WINDOWS\explorer.exe """ & strFolder & "", vbNormalFocus)


    End Sub
    Last edited by drsd32; Apr 21st, 2013 at 07:18 AM.

  6. #6
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Simple Question

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.  Dim strTrseq As Integer
    4.  Dim strTseries As Integer
    5.  Dim strPath As String
    6.  Dim strFolder As String
    7.  
    8.  strTrseq = Val(TextBox1.Text) \ 1000
    9.  strTseries = strTruckseq * 1000
    10.  
    11.  
    12.  
    13. If strTseries > 1000000 Then
    14.   strTseries = strTrseq \ 10
    15.  
    16. ElseIf strTseries < 133000 Then
    17.  MessageBox.Show("INVALID NUMBER")
    18.  TextBox1.Text = ""
    19.  Exit Sub
    20.  
    21. End If
    22.  
    23. End Sub
    Last edited by circuits2; Apr 20th, 2013 at 09:43 PM.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Re: Simple Question

    Your awesome Circuits, works perfectly. can it be done that I can enter a number in the text box and it takes it by hitting enter on the keyboad

  8. #8
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Simple Question

    Check out the AcceptButton property on your form. It sets which button is automatically pressed when the user hits Enter.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Re: Simple Question

    Cool I know I have a lot to learn, but I have to start some where. Thankyou

  10. #10
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Simple Question

    Glad you got it worked out. In the future, placing this at the top of your code will help you find the problems:

    OPTION STRICT ON
    OPTION EXPLICIT ON
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

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