Kornowski's Software

Cromewell

Administrator
Staff member
Oh...yeah...it will do that. Anywhere you have txt_display = "" you gotta change to txt_display = "0"
 

Kornowski

VIP Member
Right, I've done that, but the problem I have with it now is that there is a 0 at the begining of the text box and people won't want a 0 at the beggining of the number sequence, if that makes sense?
 

Cromewell

Administrator
Staff member
To work around that, in each button press (it's technically better to make this it's own function but it's so small there's no point), check if txt_display contains "0" (ie
If cint(txt_display.text) = 0 Then
txt_display = <number pressed>
End If
)
I don't know you you allow people to type directly into the text box but you can create a similar process for that as well as restrict what keys it will accept.
 

Kornowski

VIP Member
Dim var_First_Number As Double
Dim var_Second_Number As Double
Dim var_Operator As String

Private Sub cmd_Clear_Click()
txt_Display = ""
End Sub

Private Sub cmd_Divide_Click()
If txt_Display = "" Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Div"
txt_Display = ""
End If
End Sub

Private Sub cmd_Eight_Click()
txt_Display = txt_Display & 8
End Sub

Private Sub cmd_Equals_Click()
var_Second_Number = txt_Display
If var_Operator = "Add" Then
txt_Display = var_First_Number + var_Second_Number
ElseIf var_Operator = "Min" Then
txt_Display = var_First_Number - var_Second_Number
ElseIf var_Operator = "Div" Then
txt_Display = var_First_Number / var_Second_Number
ElseIf var_Operator = "Mul" Then
txt_Display = var_First_Number * var_Second_Number
End If
End Sub

Private Sub cmd_Five_Click()
txt_Display = txt_Display & 5
End Sub

Private Sub cmd_Four_Click()
txt_Display = txt_Display & 4
End Sub

Private Sub cmd_Nine_Click()
txt_Display = txt_Display & 9
End Sub

Private Sub cmd_Plus_Click()
If txt_Display = "" Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Add"
txt_Display = ""
End If
End Sub

Private Sub cmd_Seven_Click()
txt_Display = txt_Display & 7
End Sub

Private Sub cmd_Six_Click()
txt_Display = txt_Display & 6
End Sub

Private Sub cmd_Subtract_Click()
If txt_Display = "" Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Min"
txt_Display = ""
End If
End Sub

Private Sub cmd_Three_Click()
txt_Display = txt_Display & 3
End Sub

Private Sub cmd_Times_Click()
If txt_Display = "" Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Mul"
txt_Display = ""
End If
End Sub

Private Sub cmd_Two_Click()
txt_Display = txt_Display & 2
End Sub

Private Sub cmd_Zero_Click()
txt_Display = txt_Display & 0
End Sub

Private Sub cmd_One_Click()
txt_Display = txt_Display & 1
End Sub


Theres the code now, I've fixed the overflow issue and the problem that it closes when you click a button and there's no value entered
 

Emperor_nero

New Member
Cromewell said:
To work around that, in each button press (it's technically better to make this it's own function but it's so small there's no point), check if txt_display contains "0" (ie
If cint(txt_display.text) = 0 Then
txt_display = <number pressed>
End If
)
I don't know you you allow people to type directly into the text box but you can create a similar process for that as well as restrict what keys it will accept.

I don't think that would work, becuase that would just let the user enter one digit. (Unless they entered zero) :)

Here, I've fixed that problem I think, and a divide by zero problem. :) And good morning, or good night. :D

Dim var_First_Number As Double
Dim var_Second_Number As Double
Dim var_Operator As String

Private Sub cmd_Clear_Click()
txt_Display = 0
End Sub

Private Sub cmd_Divide_Click()
If txt_Display = 0 Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Div"
txt_Display = ""
End If
End Sub

Private Sub cmd_Eight_Click()
txt_Display = txt_Display & 8
End Sub

Private Sub cmd_Equals_Click()
var_Second_Number = txt_Display
If var_Operator = "Add" Then
txt_Display = var_First_Number + var_Second_Number
ElseIf var_Operator = "Min" Then
txt_Display = var_First_Number - var_Second_Number
ElseIf var_Operator = "Div" Then
If var_Second_Number = 0 Then
MsgBox "Error, cannot divide by zero"
Else
txt_Display = var_First_Number / var_Second_Number
End If
ElseIf var_Operator = "Mul" Then
txt_Display = var_First_Number * var_Second_Number
End If
End Sub

Private Sub cmd_Five_Click()
txt_Display = txt_Display & 5
End Sub

Private Sub cmd_Four_Click()
txt_Display = txt_Display & 4
End Sub

Private Sub cmd_Nine_Click()
txt_Display = txt_Display & 9
End Sub

Private Sub cmd_Plus_Click()
If txt_Display = 0 Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Add"
txt_Display = ""
End If
End Sub

Private Sub cmd_Seven_Click()
txt_Display = txt_Display & 7
End Sub

Private Sub cmd_Six_Click()
txt_Display = txt_Display & 6
End Sub

Private Sub cmd_Subtract_Click()
If txt_Display = 0 Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Min"
txt_Display = ""
End If
End Sub

Private Sub cmd_Three_Click()
txt_Display = txt_Display & 3
End Sub

Private Sub cmd_Times_Click()
If txt_Display = 0 Then
MsgBox "Please enter a value", , "Incorrect Function"
Else
var_First_Number = txt_Display
var_Operator = "Mul"
txt_Display = ""
End If
End Sub

Private Sub cmd_Two_Click()
txt_Display = txt_Display & 2
End Sub

Private Sub cmd_Zero_Click()
txt_Display = txt_Display & 0
End Sub

Private Sub cmd_One_Click()
txt_Display = txt_Display & 1
End Sub

Private Sub Form_Load()
txt_Display = 0
End Sub
 
Last edited:

Emperor_nero

New Member
Well you can get Microsoft Visual Basic 2005 Express Edition for free. :)
Have a good break. We just get one week of here. :p


And what's awesome? That is was fun?
 

Cromewell

Administrator
Staff member
I don't think that would work, becuase that would just let the user enter one digit. (Unless they entered zero)
Well it's not all there, I forgot to add the else branch.

If cint(txt_display.text) = 0 Then
txt_display = <number pressed>
else
txt_display = txt_display & <number>
End If

Anytime you can avoid using messageboxes is good. They are irritating.

Also, if you do let people click in the textbox and type numbers in with the keyboard, you can use the onkeydown (might be onkeypress) event to restrict what keys it will take. There might be a way with the textbox controls too but it's been a while since I've used VB6.

VB Express 2005 is a VB.NET version I think, so it will work differently than what you are used to.
 

Emperor_nero

New Member
Well it's not all there, I forgot to add the else branch.

If cint(txt_display.text) = 0 Then
txt_display = <number pressed>
else
txt_display = txt_display & <number>
End If

Now that makes more sense. :)

Anytime you can avoid using messageboxes is good. They are irritating.
True I suppose. :)

VB Express 2005 is a VB.NET version I think, so it will work differently than what you are used to.

Yeah that might be I'm not sure.
 
Last edited:

Kornowski

VIP Member
Well it's not all there, I forgot to add the else branch.

If cint(txt_display.text) = 0 Then
txt_display = <number pressed>
else
txt_display = txt_display & <number>
End If

Anytime you can avoid using messageboxes is good. They are irritating.

Also, if you do let people click in the textbox and type numbers in with the keyboard, you can use the onkeydown (might be onkeypress) event to restrict what keys it will take. There might be a way with the textbox controls too but it's been a while since I've used VB6.

VB Express 2005 is a VB.NET version I think, so it will work differently than what you are used to.


Ok thansk, I'll try it in 2 weeks, I'll get back to you :p

Yeah, They are irritating, but they may help?
I'll look in to that, because it does crash when you put text in the display.
 

Shane

Super Moderator
Staff member
ive started using the clock mate :D

quite nice,However it needs a nice icon,how do you change the icon?
 
Last edited:

Cromewell

Administrator
Staff member
You can assign an icon in VB, it's one of the form properties. I think you can only assign an icon in windows if you create a shortcut to the exe.
 

Kornowski

VIP Member
I don't have VB at home so I can't change it but I think I remember seeing something like that but it had to be a .ico format.
 
Top