Hi
Hope you all enjoy this website.
Basic program to say Hello in different languages
Option Explicit
Private Sub cmdClear_Click()
lblMessage.Caption = ""
End Sub
Private Sub cmdEnglish_Click()
‘Display the Hello World Message in English
lblMessage.Caption = "Hello World"
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdFrench_Click()
‘Display the "Hello World" Message in French
lblMessage.Caption = "Bonjour tout le monde"
End Sub
Private Sub cmdItalian_Click()
‘Display the "Hello World" Message in Italian
lblMessage.Caption = "Ciao mondo"
End Sub
Private Sub cmdSpanish_Click()
‘Display the "Hello World" Message in Spanish
lblMessage.Caption = "Hola mundo"
End Sub
Basic Program that gives the grade according to the mark given
Function Result(mark As Integer) As String
If mark < 40 Then
Result = "FAIL"
ElseIf mark >= 40 And mark <= 75 Then
Result = "PASS"
Else
Result = "DISTINCTION"
End If
End Function
Private Sub cmdClear_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub cmdClose_Click()
End
End Sub
Private Sub examGrade_Click()
Dim grade As Integer
grade = Val(Text1.Text)
Dim x As String
x = Result(grade)
Text2.Text = x
End Sub
Program that change font and format a text
Private Sub chkBold_Click()
If chkBold = 1 Then
TxtText.FontBold = True
Else
TxtText.FontBold = False
End If
End Sub
Private Sub chkItalic_Click()
If chkItalic = 1 Then
TxtText.FontItalic = True
Else
TxtText.FontItalic = False
End If
End Sub
Private Sub cmdClear_Click()
End Sub
Private Sub Form_Load()
TxtText.Text = ""
TxtText.FontSize = 12
TxtText.FontName = "Times"
TxtText.FontBold = False
TxtText.FontItalic = False
chkBolt = 0
chkItalic = 0
optTimes = True
optArial = False
End Sub
Private Sub optArial_Click()
If optArial Then
TxtText.FontName = "Arial"
End If
End Sub
Private Sub optTimes_Click()
If optTimes Then
TxtText.FontName = "Times"
End If
End Sub
Happy New Academic Year to all the Visitors and Users of this blog. Thanks for your constant support. Hope you always get what you are looking for in this blog be it programming, french or else. Peace and Love
Program that deals with textbox validation
Public Class Form1
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (Asc(e.KeyChar) < 48) Or (Asc(e.KeyChar) > 57) Then
e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) =
Then
e.Handled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim entry As Integer
entry = Val(TextBox1.Text)
If entry >= 1 And entry <= 20 Then
End
Else
MsgBox(" Table Number should be between 1 and 20")
End If
End Sub
End Class
Program that calculate bill according to user status and power consumption
Public Class Form1
Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click
Dim AccountNumb As Long
Dim PowerConsum As Integer
Dim Result As Double
AccountNumb = Val(txtAccountNumb.Text)
PowerConsum = Val(txtPowercons.Text)
If RadioButton1.Checked = True Then
Result = (6.52 * PowerConsum)
ElseIf RadioButton2.Checked = True Then
If PowerConsum <= 1000 Then
Result = 60
Else
Result = 60 + (4.5 * (PowerConsum - 1000))
End If
ElseIf RadioButton3.Checked = True Then
If PowerConsum <= 1000 Then
Result = 76
Else
Result = 76 + (6.5 * (PowerConsum - 1000))
End If
End If
txtResult.Text = Result
End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Me.Close()
End Sub
Private Sub txtAccountNumb_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAccountNumb.KeyPress
If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
MsgBox("Please enter numbers only ")
End If
End Sub
Private Sub txtPowerCons_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPowerCons.KeyPress
If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
MsgBox("Please enter numbers only ")
End If
End Sub
End Class
Program that converts from celcius to fahrenheit and display result to other textbox
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim value As Single
value = Val(TextBox1.Text)
TextBox2.Text = ((value * 9 / 5) + 32)
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Dim value2 As Single
value2 = Val(TextBox2.Text)
TextBox1.Text = ((value2 - 32) * 5 / 9)
End Sub
End Class
Program that split a paragraph into words and save it into a list box
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim textentered As String
‘get the text entered in the text box
textentered = myTextBox1.Text
Dim words As String() = SplitWords(textentered)
Dim word As String
‘loop through each word to display them in the listbox
For Each word In words
myListBox1.Items.Add(word)
Next
‘display the number of words found
Label3.Text = myListBox1.Items.Count & " words typed"
End Sub
Private Function SplitWords(ByVal s As String) As String()
Return Regex.Split(s, "\W+")
End Function
End Class
Program that guess age in vb
Public Class Form1
Dim ageguesser As New Random()
Dim current As Integer
Dim toolow As Integer
Dim toohigh As Integer
Dim correct As Integer
Dim tries As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Integer.Parse(ageguesser.Next(5, 110))
current = Label1.Text
tries = tries + 1
toohigh = Integer.Parse(ageguesser.Next(5, 110))
toolow = Integer.Parse(ageguesser.Next(5, 110))
correct = Integer.Parse(ageguesser.Next(5, 110))
If current > toohigh Then
MessageBox.Show("your guess was too high. toohigh was " & toohigh)
current = Integer.Parse(ageguesser.Next(5, (110 - 1)))
ElseIf current < toolow Then
MessageBox.Show("your guess was too low. toolow was " & toolow)
current = Integer.Parse(ageguesser.Next((current + 1), 110))
ElseIf current = correct Then
MessageBox.Show("Your guess was correct. correct was " & correct)
MessageBox.Show("you have" & tries)
Else
MessageBox.Show("you have " & tries & " so far")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
|
|
|




