Difference between ByVal and ByRef

  • Thread starter Thread starter Amr_Aly
  • Start date Start date
A

Amr_Aly

Guest
Hi, Everyone

This Snippet of code doesn't work , Could i know why ???

Sub CheckF14Pic(ByVal TableName As String,
ByVal ColumnName As String,
ByVal pic1 As Image,
ByVal coloredpic As Image,
ByVal graypic As Image,
Optional chx1 As Boolean = False,
Optional txt As String = "")
Using conn As New SqlConnection(cs)
conn.Open()
Using cmd As New SqlCommand()
cmd.Connection = conn
cmd.CommandText = String.Format("select {0}
from {1}
where {0}=1", ColumnName, TableName)
Using rdr As SqlDataReader = cmd.ExecuteReader()
If rdr.Read Then

MessageBox.Show("This flat is Booked, Choose another one", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

If Not rdr Is Nothing Then
rdr.Close()
End If

Else
Select Case True
Case pic1 IsNot coloredpic 'picbox44
pic1 = coloredpic 'picbox44
chx1 = True
txt = Val(txt) + 1
Exit Sub
End Select
Select Case True
Case pic1 IsNot graypic
pic1 = graypic 'picbox59
chx1 = False
txt = Val(txt) - 1
End Select
End If

End Using
End Using
End Using

End Sub
Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
CheckF14Pic("UnitA", "F4",
PictureBox4.BackgroundImage,
PictureBox44.BackgroundImage,
PictureBox59.BackgroundImage,
CheckBox4.Checked,
txtUNA.Text)
End Sub

But if i put it like this

Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
Using conn As New SqlConnection(cs)
conn.Open()
Using cmd As New SqlCommand()
cmd.Connection = conn
cmd.CommandText = "select F4
from UnitA
where F4=1"
Using rdr As SqlDataReader = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("This Flat is Booked ,Choose another one", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

If Not rdr Is Nothing Then
rdr.Close()
End If

Else
Select Case True
Case PictureBox4.BackgroundImage IsNot PictureBox44.BackgroundImage 'Colored
PictureBox4.BackgroundImage = PictureBox44.BackgroundImage
CheckBox4.Checked = True
txtUNA.Text = Val(txtUNA.Text) + 1
Exit Sub
End Select
Select Case True
Case PictureBox4.BackgroundImage IsNot PictureBox59.BackgroundImage
PictureBox4.BackgroundImage = PictureBox59.BackgroundImage 'Gray
CheckBox4.Checked = False
txtUNA.Text = Val(txtUNA.Text) - 1
End Select

End If

End Using
End Using
End Using
End Sub

It works , Could i find any guide ,,,

Also in a Sub of loading from database it looks like this




Regards From Egypt

Continue reading...
 
Back
Top