I'm learning VB in my school, and i have some homework this weekend. my problem is i've forgotten the proper prefix for a frame, i thought frm, but thats for the form, so whats a frame?
Last edited by GW2live; Feb 17th, 2008 at 03:35 PM.
There is no such thing as "proer prefix" - most people would use "fra" but it isn't necessary.
You can name your control anyhow you wish - just don't keep the default name and try always changing it to something meaningful:
my teacher insists that we use them, fra seems to be correct. thanks for the help. i may need a little more so ill just post here rather then making a new thread if it comes to that.
I always use fra, some my forms have 10,000 lines of code, when searching for a frame in the Properties combo they are always grouped together
fraTaxOptions
fraProfitOptions
fraPrintOptions and always use Mixed case
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
Alright well I need help again. I uploaded what i have (which isnt much) all i've done is porgrammed the done button. But what i have to do is make the frame disabled if the value of either text box is 0. im typing what i wrote but it doesnt work. what i wrote was
Code:
fraFunction.Enabled =False if txtNum1.Text = 0
but it doesnt work, I need to make it only recognise text as integer as well but I forget how, I want to learn I dont want it done for me, so if someone could maybe edit mine upload it then I could see how they did it or just tell me what I need to do.
Last edited by GW2live; Feb 17th, 2008 at 03:33 PM.
Sub numbersOnly(KeyAscii As Integer, txtBox As TextBox)
On Error GoTo e
If KeyAscii <> 8 And KeyAscii <> 45 And KeyAscii <> 46 And KeyAscii <> 13 Then
If Chr(KeyAscii) < "0" Or Chr(KeyAscii) > "9" Then
KeyAscii = 0
Beep
End If
End If
If InStr(txtBox, ".") Then 'only allow 1 decimal
If KeyAscii = 46 Then KeyAscii = 0
Exit Sub
End If
If Len(txtBox.Text) > 0 And KeyAscii = 45 Then 'only allow minus sign in leftmost position
KeyAscii = 0
End If
Exit Sub
e:
MsgBox "numbersOnly" & err.number & " " & err.Description
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
woah. that just went clean over my head. im doing basic basic stuff here. that is definatley not the way he shwoed us how to do it. (mind you he didnt show us much) now my brain hurts.
woah. that just went clean over my head. im doing basic basic stuff here. that is definatley not the way he shwoed us how to do it. (mind you he didnt show us much) now my brain hurts.
just call it like this:
Private Sub text1_KeyPress(KeyAscii As Integer)
numbersOnly KeyAscii, text1
Exit Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
In case you haven't realised, the form of the If statement is the other way round to the way you tried
Code:
fraFunction.Enabled =False if txtNum1.Text = 0
should be
Code:
If txtNum1.Text = 0 Then fraFunction.Enabled = False
In general, the If statement syntax is:
Code:
If <some condition> Then
'
' Code goes here if <some condition> evaluates to True
'
Else
'
' Code goes here if <some condition> evaluates to False
'
End If
The Else clause is optional but the End If is mandatory unless the whole statement is on one line. So
Code:
If x <> 0 Then Y = 20
is valid, as is
Code:
If X <> 0 Then
Y = 20
End If
but
Code:
If X <> 0 Then
Y = 20
is not valid.
A couple of general tips in case your Teacher doesn't insist on them:
(a) Always put Option Explicit in the Declarations Section of your Form. It forces you to define all the variables you use and will save you countless hours of debugging.
(b) Indent your code (eg as I have done with the If / Then / Else / End If above) when you use If / Select Case / Do / For / and any other statements that are executed in "Blocks". IT makes the code easier to read and understand and also it's fairly obvious is you've missed things like End If off a block of code
eg
Code:
If X = 20 Then
If y=30 Then
z=4
Else
z=7
End If
q=34
In the above it's not too obvious that there's an End If missing, whereas
Code:
If X = 20 Then
If Y = 30 Then
z=4
Else
z=7
End If
q = 34
It's fairly obvious that there's an End If missing just by looking at the indentation.
Last edited by Doogle; Feb 18th, 2008 at 02:44 AM.