-
Apr 20th, 2013, 08:10 PM
#1
Thread Starter
New Member
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
-
Apr 20th, 2013, 08:27 PM
#2
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?
-
Apr 20th, 2013, 09:00 PM
#3
Thread Starter
New Member
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.
-
Apr 20th, 2013, 09:03 PM
#4
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?
-
Apr 20th, 2013, 09:24 PM
#5
Thread Starter
New Member
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.
-
Apr 20th, 2013, 09:33 PM
#6
Re: Simple Question
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strTrseq As Integer Dim strTseries As Integer Dim strPath As String Dim strFolder As String strTrseq = Val(TextBox1.Text) \ 1000 strTseries = strTruckseq * 1000 If strTseries > 1000000 Then strTseries = strTrseq \ 10 ElseIf strTseries < 133000 Then MessageBox.Show("INVALID NUMBER") TextBox1.Text = "" Exit Sub End If End Sub
Last edited by circuits2; Apr 20th, 2013 at 09:43 PM.
-
Apr 20th, 2013, 09:46 PM
#7
Thread Starter
New Member
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
-
Apr 20th, 2013, 09:53 PM
#8
Re: Simple Question
Check out the AcceptButton property on your form. It sets which button is automatically pressed when the user hits Enter.
-
Apr 20th, 2013, 09:59 PM
#9
Thread Starter
New Member
Re: Simple Question
Cool I know I have a lot to learn, but I have to start some where. Thankyou
-
Apr 20th, 2013, 10:02 PM
#10
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|