473,699 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help needed returning variable values.

Complete code follows.

I am new to .NET programming (and programming in general) and I am having a
difficult time understanding how to fill a variable in one sub, and then
access it from another. I have tried declaring them as shared, public,
friend, etc and I always get an error stating that something is not valid
on a local variable declaration.

For example, in the following code for Sub DataGrid_Select , I have
CurrentID and CurrentActID being populated with the values of a specific
datagrid cell. Later, in the Button2_Click event, I need to get the value
of those variables to create a SQL update command, but I cannot find the...
namespace, I guess is what I need, for that variable.

In a similar situation, you can see that I am rewriting my SQL connection
code for every routine that needs to access the DB. I created Function
DBConnect, and would like to call that in place of where I am writing the
full code, but I am not able to retuen the sqlcon object to the calling
sub. What am I doing wrong?

Can anyone explain the correct way of doing these things?

Public Class WebForm1
Inherits System.Web.UI.P age
Protected WithEvents DropDownList1 As
System.Web.UI.W ebControls.Drop DownList
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label2 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label3 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label4 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label5 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label6 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label7 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label8 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label9 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label10 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Button2 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Label11 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label12 As System.Web.UI.W ebControls.Labe l
Protected WithEvents CheckBoxList1 As
System.Web.UI.W ebControls.Chec kBoxList
Protected WithEvents txtFullname As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtCompany As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtTitle As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtConfNotes As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtActDate As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtFollowUpDate As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtBPhone As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtWorkExt As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label13 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtSearchDate As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label14 As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents Label15 As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid2 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents txtClientCell As System.Web.UI.W ebControls.Text Box
Protected WithEvents Button3 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Button4 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Label16 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label17 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label18 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label19 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtNotes As System.Web.UI.W ebControls.Text Box

Dim CurrentActivity ID As String
Dim CurrentID As String

#Region " Web Form Designer Generated Code "
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

#Region " Developer Generated Code "

Function DBConnect()
Dim sqlcon As New SqlClient.SqlCo nnection() ' Dim new SQL
connection object
sqlcon.Connecti onString = "Server=Boca2;U ser
ID=ID;password= PASS;Database=P ursuittest" ' Connection string
sqlcon.Open() ' Open a connection to the DB
Return sqlcon
End Function

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Utilities.Creat eConfirmBox(Me. Button2, _
"Are you sure you want to update the record?")
End Sub

Sub UpdateLabels()
'Shows page count for DG paging events
Label14.Text = "Displaying page " & (DataGrid1.Curr entPageIndex +
1).ToString() & " of " & DataGrid1.PageC ount
End Sub

Sub DrawData()
Dim ColumnNames ' Used to define selected columns
Dim OrderClause ' Used to specify ordering
Dim WhereClause ' Used to specify Database for query and concat.
first part of SQL statement
Dim Criteria ' Used to define query criteria
Dim UserName ' Used for determining user. Not Implemented.
Dim sqlcmd0 As New SqlClient.SqlCo mmand() ' Dim new SQL command
object
'Dim sqlcon As New SqlClient.SqlCo nnection() ' Dim new SQL
connection object

'DBConnect()
Dim sqlcon As New SqlClient.SqlCo nnection() ' Dim new SQL
connection object
sqlcon.Connecti onString = "Server=Boca2;U ser
ID=ID;password= PASS;Database=P ursuittest" ' Connection string
sqlcon.Open() ' Open a connection to the DB

Dim ds As New DataSet() ' Dim new Dataset
Dim da As New SqlClient.SqlDa taAdapter() ' Dim new SQL data adapter
object
'sqlcon.Connect ionString = "Server=Boca2;U ser
ID=sa;password= fdstemers;Datab ase=Pursuittest " ' Connection string
sqlcmd0.Connect ion = sqlcon ' Telling the SQL Command object which
connection to use
'sqlcon.Open() ' Open a connection to the DB
ColumnNames = "Client_Name_La st as Last, Client_Name_Fir st as
First, Client_Name_Ful l as FullName, Client_Title_Lo ng as Title,
Client_Title_CD as TitleCode, Client_Company as Company, Activity_Agent as
Agent, Activity_Date as ActivityDate, Activity_Follow Up as FollowUpDate,
Activity_Notes as Notes, Activity_Notes_ Confidential as Confidential,
Client_BEmail as BEmail, Client_BPhone, Client_BPhone_E xt, Client_Cell,
Client_Person_I D, Activity_ID" 'Use these column names for select query
WhereClause = "SELECT " & ColumnNames & " FROM Searches_Activi ty
WHERE " ' Building the first part of the SQL query
Criteria = "(Activity_Acti vity_CD = 2) and (Activity_Date >='" &
txtSearchDate.T ext() & "') and (Activity_agent ='" &
DropDownList1.S electedItem.Tex t & "')" ' SQL Select criteria
Criteria = Mid(Criteria, 1, Len(Criteria) - 1) & ")" ' Not sure
why, but this trims the last character from CRITERIA and adds a right
parenthesis
OrderClause = " ORDER BY Activity_Follow Up DESC" ' Ordering the
recordset
sqlcmd0.Command Text = WhereClause & Criteria & OrderClause '
Telling the SQL Command Object what to use for the command text by
concatonating WHERECLAUSE, CRITERIA, and, ORDERCLAUSE
da.SelectComman d = sqlcmd0 ' Telling the SQL data adaper object
which command to use
da.Fill(ds, "SA") ' Fill the DS dataset and call that table SA
sqlcon.Close() ' Close the SQL Connection
DataGrid1.DataS ource = ds 'Define which dataset to be used by
datagrid1
DataGrid1.DataK eyField = "Client_Person_ ID" ' Define a primary key
for the Dataset
DataGrid1.DataB ind() 'Bind the datagrid to it's datasource
Label13.Text = ds.Tables("SA") .Rows.Count.ToS tring & " Records
Found" ' Fill the label with the number of records in the data set DS
End Sub

Sub FillTextBoxes(B yVal e As DataGridCommand EventArgs)

If e.Item.Cells(1) .Text.Equals("& nbsp;") Then
txtFullname.Tex t = ""
Else
txtFullname.Tex t = e.Item.Cells(1) .Text
End If
If e.Item.Cells(2) .Text.Equals("& nbsp;") Then
txtTitle.Text = ""
Else
txtTitle.Text = e.Item.Cells(2) .Text
End If
If e.Item.Cells(3) .Text.Equals("& nbsp;") Then
txtCompany.Text = ""
Else
txtCompany.Text = e.Item.Cells(3) .Text
End If
If e.Item.Cells(4) .Text.Equals("& nbsp") Then
txtActDate.Text = ""
Else
txtActDate.Text = e.Item.Cells(4) .Text
End If
If e.Item.Cells(5) .Text.Equals("& nbsp;") Then
txtFollowUpDate .Text = ""
Else
txtFollowUpDate .Text = e.Item.Cells(5) .Text
End If
If e.Item.Cells(6) .Text.Equals("& nbsp;") Then
txtBPhone.Text = ""
Else
txtBPhone.Text = e.Item.Cells(6) .Text
End If
If e.Item.Cells(7) .Text.Equals("& nbsp;") Then
txtWorkExt.Text = ""
Else
txtWorkExt.Text = e.Item.Cells(7) .Text
End If
If e.Item.Cells(8) .Text.Equals("& nbsp;") Then
txtClientCell.T ext = ""
Else
txtClientCell.T ext = e.Item.Cells(8) .Text
End If
If e.Item.Cells(9) .Text.Equals("& nbsp;") Then
txtNotes.Text = ""
Else
txtNotes.Text = e.Item.Cells(9) .Text
End If
If e.Item.Cells(10 ).Text.Equals(" &nbsp;") Then
txtConfNotes.Te xt = ""
Else
txtConfNotes.Te xt = e.Item.Cells(10 ).Text
End If
End Sub

Sub ClearTextBoxes( )
'Clears text from textboxes
txtFullname.Tex t() = ""
txtTitle.Text() = ""
txtCompany.Text () = ""
txtNotes.Text() = ""
txtConfNotes.Te xt() = ""
txtActDate.Text () = ""
txtFollowUpDate .Text() = ""
txtBPhone.Text( ) = ""
txtWorkExt.Text () = ""
txtClientCell.T ext() = ""
End Sub

Sub DataGrid1_Pagin g(ByVal sender As Object, ByVal e As
DataGridPageCha ngedEventArgs)
DataGrid1.Curre ntPageIndex = e.NewPageIndex ' tell the datagrid
that we are on a new page
DrawData() ' Call Drawdata to fill the dataset and bind the
datagrid
UpdateLabels() ' call to update labels to show record and page
counts
ClearTextBoxes( )
DataGrid1.Selec tedIndex = -1 ' Tell the datagrid that nothing is
selected
End Sub

Sub DataGrid_Select (ByVal sender As Object, ByVal e As
DataGridCommand EventArgs)
Dim CurrentID = e.Item.Cells(11 ).Text.ToString
Dim CurrentActivity ID = e.Item.Cells(12 ).Text.ToString
Dim sqlcmd0 As New SqlClient.SqlCo mmand()
Dim sqlcon As New SqlClient.SqlCo nnection()
Dim ds2 As New DataSet()
Dim da2 As New SqlClient.SqlDa taAdapter()
sqlcon.Connecti onString = "Server=Boca2;U ser
ID=ID;password= PASS;Database=P ursuittest"
sqlcmd0.Connect ion = sqlcon
sqlcon.Open()
sqlcmd0.Command Text = "select BDCallsMade as 'Calls Made',
BDEmailsSent as 'Emails Sent', activity_ID, company.company as 'Company
Name', date as 'Activity Date', followup as 'Follow Up Date', notes as
Notes, notes_confident ial as Confidential from activity Activity INNER JOIN
Company ON Activity.Client _Company_ID = Company.Company _ID where
(activity_cd = 2 and client_id =" & CurrentID & ") order by date Desc"
da2.SelectComma nd = sqlcmd0
da2.Fill(ds2, "Person")

sqlcon.Close()
DataGrid2.DataS ource = ds2
'DataGrid2.Data Bind()
FillTextBoxes(e )
'DataGrid2.Visi ble = True
Label18.Visible = True
Label18.Text = ds2.Tables("Per son").Rows(0).I tem(0).ToString
Label19.Visible = True
Label19.Text = ds2.Tables("Per son").Rows(0).I tem(1).ToString
Button3.Visible = True
Button4.Visible = True
Label16.Visible = True
Label17.Visible = True
Button3.Enabled = True
Button4.Enabled = True
'DataGrid1.Visi ble = False
End Sub

Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

ClearTextBoxes( ) 'Clear Data from textboxes

DrawData() 'Query for data

DataGrid1.Curre ntPageIndex = 0 ' Returns DG to page 0

UpdateLabels() ' call to update labels to show record and page
counts

'Scorecard buttons and labels are hidden when a query is issued
'-->
Button3.Enabled = True
Button4.Enabled = True
Label16.Visible = False
Label17.Visible = False
Label18.Visible = False
Label19.Visible = False
Button3.Visible = False
Button4.Visible = False
'<--

'DataGrid1.Visi ble = True '>> Used to show second DG with activity
history
'DataGrid2.Visi ble = False '>> Used to show second DG with activity
history

End Sub

Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Button3.Enabled = True
Button4.Enabled = True
Label16.Visible = False
Label17.Visible = False
Label18.Visible = False
Label19.Visible = False
Button3.Visible = False
Button4.Visible = False
ClearTextBoxes( )
'DataGrid2.Visi ble = False
'DataGrid1.Visi ble = True
End Sub

Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Label18.Text = Label18.Text + 1
Button3.Enabled = False
End Sub

Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Label19.Text = Label19.Text + 1
Button4.Enabled = False

End Sub

#End Region
End Class
Public Class Utilities
#Region " Utility "
Public Shared Sub CreateConfirmBo x(ByRef btn As WebControls.But ton, _
ByVal strMessage As String)
btn.Attributes. Add("onclick", "return confirm('" & strMessage &
"');")
End Sub
#End Region
End Class

Nov 20 '05 #1
7 2192
rdi
There are a couple different ways to access variables globally.

First: I'll assume for a minute that you're creating a windows form type
program--when you create your form in VS.Net, the whole thing is a class
with a collection of subs, functions and varialbles.

Public Class Form1
public myVar1 as integer
private sub mySub1()
myVar1 = 1
end sub
private sub mySub2()
dim mv as integer
mv = myVar1
msgbox(mv.tostr ing)
end sub
end Class

Second: Functions return variables while subs do NOT.
public class form1
private function myFunc() as integer
dim myVar1 as integer
myVar1 = 10
return myVar1
end function
private sub()
dim mv as integer
mv = myFunc()
msgbox(mv.tostr ing)
end sub
end class

Lastly, functions and subs can either accept arguments or not accept
arguments, that's the programmer's choice. I could have defined ANY of
these functions, subs and/or variables as public, private or whatever else I
needed based on what I needed them to do.

HTH.
--

RDI

(remove the exclamation from the email address)

"Aaron" <a_******@hotma il.com> wrote in message
news:Xn******** *************** ********@207.46 .248.16...
Complete code follows.

I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then
access it from another. I have tried declaring them as shared, public,
friend, etc and I always get an error stating that something is not valid
on a local variable declaration.

For example, in the following code for Sub DataGrid_Select , I have
CurrentID and CurrentActID being populated with the values of a specific
datagrid cell. Later, in the Button2_Click event, I need to get the value
of those variables to create a SQL update command, but I cannot find the... namespace, I guess is what I need, for that variable.

In a similar situation, you can see that I am rewriting my SQL connection
code for every routine that needs to access the DB. I created Function
DBConnect, and would like to call that in place of where I am writing the
full code, but I am not able to retuen the sqlcon object to the calling
sub. What am I doing wrong?

Can anyone explain the correct way of doing these things?

Public Class WebForm1
Inherits System.Web.UI.P age
Protected WithEvents DropDownList1 As
System.Web.UI.W ebControls.Drop DownList
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label2 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label3 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label4 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label5 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label6 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label7 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label8 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label9 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label10 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Button2 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Label11 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label12 As System.Web.UI.W ebControls.Labe l
Protected WithEvents CheckBoxList1 As
System.Web.UI.W ebControls.Chec kBoxList
Protected WithEvents txtFullname As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtCompany As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtTitle As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtConfNotes As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtActDate As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtFollowUpDate As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtBPhone As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtWorkExt As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label13 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtSearchDate As System.Web.UI.W ebControls.Text Box Protected WithEvents Label14 As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents Label15 As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid2 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents txtClientCell As System.Web.UI.W ebControls.Text Box Protected WithEvents Button3 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Button4 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Label16 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label17 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label18 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label19 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtNotes As System.Web.UI.W ebControls.Text Box

Dim CurrentActivity ID As String
Dim CurrentID As String

#Region " Web Form Designer Generated Code "
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

#Region " Developer Generated Code "

Function DBConnect()
Dim sqlcon As New SqlClient.SqlCo nnection() ' Dim new SQL
connection object
sqlcon.Connecti onString = "Server=Boca2;U ser
ID=ID;password= PASS;Database=P ursuittest" ' Connection string
sqlcon.Open() ' Open a connection to the DB
Return sqlcon
End Function

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Utilities.Creat eConfirmBox(Me. Button2, _
"Are you sure you want to update the record?")
End Sub

Sub UpdateLabels()
'Shows page count for DG paging events
Label14.Text = "Displaying page " & (DataGrid1.Curr entPageIndex +
1).ToString() & " of " & DataGrid1.PageC ount
End Sub

Sub DrawData()
Dim ColumnNames ' Used to define selected columns
Dim OrderClause ' Used to specify ordering
Dim WhereClause ' Used to specify Database for query and concat.
first part of SQL statement
Dim Criteria ' Used to define query criteria
Dim UserName ' Used for determining user. Not Implemented.
Dim sqlcmd0 As New SqlClient.SqlCo mmand() ' Dim new SQL command
object
'Dim sqlcon As New SqlClient.SqlCo nnection() ' Dim new SQL
connection object

'DBConnect()
Dim sqlcon As New SqlClient.SqlCo nnection() ' Dim new SQL
connection object
sqlcon.Connecti onString = "Server=Boca2;U ser
ID=ID;password= PASS;Database=P ursuittest" ' Connection string
sqlcon.Open() ' Open a connection to the DB

Dim ds As New DataSet() ' Dim new Dataset
Dim da As New SqlClient.SqlDa taAdapter() ' Dim new SQL data adapter object
'sqlcon.Connect ionString = "Server=Boca2;U ser
ID=sa;password= fdstemers;Datab ase=Pursuittest " ' Connection string
sqlcmd0.Connect ion = sqlcon ' Telling the SQL Command object which
connection to use
'sqlcon.Open() ' Open a connection to the DB
ColumnNames = "Client_Name_La st as Last, Client_Name_Fir st as
First, Client_Name_Ful l as FullName, Client_Title_Lo ng as Title,
Client_Title_CD as TitleCode, Client_Company as Company, Activity_Agent as
Agent, Activity_Date as ActivityDate, Activity_Follow Up as FollowUpDate,
Activity_Notes as Notes, Activity_Notes_ Confidential as Confidential,
Client_BEmail as BEmail, Client_BPhone, Client_BPhone_E xt, Client_Cell,
Client_Person_I D, Activity_ID" 'Use these column names for select query
WhereClause = "SELECT " & ColumnNames & " FROM Searches_Activi ty
WHERE " ' Building the first part of the SQL query
Criteria = "(Activity_Acti vity_CD = 2) and (Activity_Date >='" &
txtSearchDate.T ext() & "') and (Activity_agent ='" &
DropDownList1.S electedItem.Tex t & "')" ' SQL Select criteria
Criteria = Mid(Criteria, 1, Len(Criteria) - 1) & ")" ' Not sure
why, but this trims the last character from CRITERIA and adds a right
parenthesis
OrderClause = " ORDER BY Activity_Follow Up DESC" ' Ordering the
recordset
sqlcmd0.Command Text = WhereClause & Criteria & OrderClause '
Telling the SQL Command Object what to use for the command text by
concatonating WHERECLAUSE, CRITERIA, and, ORDERCLAUSE
da.SelectComman d = sqlcmd0 ' Telling the SQL data adaper object
which command to use
da.Fill(ds, "SA") ' Fill the DS dataset and call that table SA
sqlcon.Close() ' Close the SQL Connection
DataGrid1.DataS ource = ds 'Define which dataset to be used by
datagrid1
DataGrid1.DataK eyField = "Client_Person_ ID" ' Define a primary key
for the Dataset
DataGrid1.DataB ind() 'Bind the datagrid to it's datasource
Label13.Text = ds.Tables("SA") .Rows.Count.ToS tring & " Records
Found" ' Fill the label with the number of records in the data set DS
End Sub

Sub FillTextBoxes(B yVal e As DataGridCommand EventArgs)

If e.Item.Cells(1) .Text.Equals("& nbsp;") Then
txtFullname.Tex t = ""
Else
txtFullname.Tex t = e.Item.Cells(1) .Text
End If
If e.Item.Cells(2) .Text.Equals("& nbsp;") Then
txtTitle.Text = ""
Else
txtTitle.Text = e.Item.Cells(2) .Text
End If
If e.Item.Cells(3) .Text.Equals("& nbsp;") Then
txtCompany.Text = ""
Else
txtCompany.Text = e.Item.Cells(3) .Text
End If
If e.Item.Cells(4) .Text.Equals("& nbsp") Then
txtActDate.Text = ""
Else
txtActDate.Text = e.Item.Cells(4) .Text
End If
If e.Item.Cells(5) .Text.Equals("& nbsp;") Then
txtFollowUpDate .Text = ""
Else
txtFollowUpDate .Text = e.Item.Cells(5) .Text
End If
If e.Item.Cells(6) .Text.Equals("& nbsp;") Then
txtBPhone.Text = ""
Else
txtBPhone.Text = e.Item.Cells(6) .Text
End If
If e.Item.Cells(7) .Text.Equals("& nbsp;") Then
txtWorkExt.Text = ""
Else
txtWorkExt.Text = e.Item.Cells(7) .Text
End If
If e.Item.Cells(8) .Text.Equals("& nbsp;") Then
txtClientCell.T ext = ""
Else
txtClientCell.T ext = e.Item.Cells(8) .Text
End If
If e.Item.Cells(9) .Text.Equals("& nbsp;") Then
txtNotes.Text = ""
Else
txtNotes.Text = e.Item.Cells(9) .Text
End If
If e.Item.Cells(10 ).Text.Equals(" &nbsp;") Then
txtConfNotes.Te xt = ""
Else
txtConfNotes.Te xt = e.Item.Cells(10 ).Text
End If
End Sub

Sub ClearTextBoxes( )
'Clears text from textboxes
txtFullname.Tex t() = ""
txtTitle.Text() = ""
txtCompany.Text () = ""
txtNotes.Text() = ""
txtConfNotes.Te xt() = ""
txtActDate.Text () = ""
txtFollowUpDate .Text() = ""
txtBPhone.Text( ) = ""
txtWorkExt.Text () = ""
txtClientCell.T ext() = ""
End Sub

Sub DataGrid1_Pagin g(ByVal sender As Object, ByVal e As
DataGridPageCha ngedEventArgs)
DataGrid1.Curre ntPageIndex = e.NewPageIndex ' tell the datagrid
that we are on a new page
DrawData() ' Call Drawdata to fill the dataset and bind the
datagrid
UpdateLabels() ' call to update labels to show record and page
counts
ClearTextBoxes( )
DataGrid1.Selec tedIndex = -1 ' Tell the datagrid that nothing is
selected
End Sub

Sub DataGrid_Select (ByVal sender As Object, ByVal e As
DataGridCommand EventArgs)
Dim CurrentID = e.Item.Cells(11 ).Text.ToString
Dim CurrentActivity ID = e.Item.Cells(12 ).Text.ToString
Dim sqlcmd0 As New SqlClient.SqlCo mmand()
Dim sqlcon As New SqlClient.SqlCo nnection()
Dim ds2 As New DataSet()
Dim da2 As New SqlClient.SqlDa taAdapter()
sqlcon.Connecti onString = "Server=Boca2;U ser
ID=ID;password= PASS;Database=P ursuittest"
sqlcmd0.Connect ion = sqlcon
sqlcon.Open()
sqlcmd0.Command Text = "select BDCallsMade as 'Calls Made',
BDEmailsSent as 'Emails Sent', activity_ID, company.company as 'Company
Name', date as 'Activity Date', followup as 'Follow Up Date', notes as
Notes, notes_confident ial as Confidential from activity Activity INNER JOIN Company ON Activity.Client _Company_ID = Company.Company _ID where
(activity_cd = 2 and client_id =" & CurrentID & ") order by date Desc"
da2.SelectComma nd = sqlcmd0
da2.Fill(ds2, "Person")

sqlcon.Close()
DataGrid2.DataS ource = ds2
'DataGrid2.Data Bind()
FillTextBoxes(e )
'DataGrid2.Visi ble = True
Label18.Visible = True
Label18.Text = ds2.Tables("Per son").Rows(0).I tem(0).ToString
Label19.Visible = True
Label19.Text = ds2.Tables("Per son").Rows(0).I tem(1).ToString
Button3.Visible = True
Button4.Visible = True
Label16.Visible = True
Label17.Visible = True
Button3.Enabled = True
Button4.Enabled = True
'DataGrid1.Visi ble = False
End Sub

Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

ClearTextBoxes( ) 'Clear Data from textboxes

DrawData() 'Query for data

DataGrid1.Curre ntPageIndex = 0 ' Returns DG to page 0

UpdateLabels() ' call to update labels to show record and page
counts

'Scorecard buttons and labels are hidden when a query is issued
'-->
Button3.Enabled = True
Button4.Enabled = True
Label16.Visible = False
Label17.Visible = False
Label18.Visible = False
Label19.Visible = False
Button3.Visible = False
Button4.Visible = False
'<--

'DataGrid1.Visi ble = True '>> Used to show second DG with activity history
'DataGrid2.Visi ble = False '>> Used to show second DG with activity history

End Sub

Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Button3.Enabled = True
Button4.Enabled = True
Label16.Visible = False
Label17.Visible = False
Label18.Visible = False
Label19.Visible = False
Button3.Visible = False
Button4.Visible = False
ClearTextBoxes( )
'DataGrid2.Visi ble = False
'DataGrid1.Visi ble = True
End Sub

Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Label18.Text = Label18.Text + 1
Button3.Enabled = False
End Sub

Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Label19.Text = Label19.Text + 1
Button4.Enabled = False

End Sub

#End Region
End Class
Public Class Utilities
#Region " Utility "
Public Shared Sub CreateConfirmBo x(ByRef btn As WebControls.But ton, _
ByVal strMessage As String)
btn.Attributes. Add("onclick", "return confirm('" & strMessage &
"');")
End Sub
#End Region
End Class

Nov 20 '05 #2
Thank you for the insight. I'm actually developing an asp.net web form
application. Do variables act any differently in this environment?
Aaron
"rdi" <rd**@writeme.c om> wrote in
news:eH******** ******@TK2MSFTN GP12.phx.gbl:
There are a couple different ways to access variables globally.

First: I'll assume for a minute that you're creating a windows form
type program--when you create your form in VS.Net, the whole thing is
a class with a collection of subs, functions and varialbles.
......

Nov 20 '05 #3
> Thank you for the insight. I'm actually developing an asp.net web form
application. Do variables act any differently in this environment?


As far as I know is the only real difference that they have normally, even
when they are made public on the form, have no longer livetime than the page
and that therefore when the page is sended every thing is gone.

I hope this helps?

Cr
Nov 20 '05 #4
Aaron,

Sorry about that--I didn't have time to actually read through your
code. Otherwise I would've seen that you weren't making a windows
form. As it was, I only read that you wanted to know how to use
variables throughout your program. And responded to that request.

I don't know anything about ASP.net but I would have to believe that
it's the same.

Aaron <a_******@hotma il.com> wrote in message news:<Xn******* *************** **********@207. 46.248.16>...
Thank you for the insight. I'm actually developing an asp.net web form
application. Do variables act any differently in this environment?
Aaron
"rdi" <rd**@writeme.c om> wrote in
news:eH******** ******@TK2MSFTN GP12.phx.gbl:
There are a couple different ways to access variables globally.

First: I'll assume for a minute that you're creating a windows form
type program--when you create your form in VS.Net, the whole thing is
a class with a collection of subs, functions and varialbles.
......

Nov 20 '05 #5
Hi Don,

I did not look to what you wrote to Aaron when I answered his last question,
however I did it now and could not find anything that is different in your
samples on a windowform or a webform.

I hope this helps.

Cor
Sorry about that--I didn't have time to actually read through your
code. Otherwise I would've seen that you weren't making a windows
form. As it was, I only read that you wanted to know how to use
variables throughout your program. And responded to that request.

I don't know anything about ASP.net but I would have to believe that
it's the same.

Nov 20 '05 #6
OK, I tried the code, but I am still getting "Nothing" as the value of my
variable.

Here is what I am doing:

Outside of any event handler I have the following lines:

Public CurrentID As String
Public CurrentActivity ID As String

Then I have a Datagrid select event. You can see that I am loading these
variables with the contents of a DG cell.

Sub DataGrid_Select (ByVal sender As Object, ByVal e As
DataGridCommand EventArgs)
CurrentID = e.Item.Cells(11 ).Text.ToString
CurrentActivity ID = e.Item.Cells(12 ).Text.ToString
Dim sqlcmd0 As New SqlClient.SqlCo mmand()
Dim sqlcon = DBConnect() ' Dim new SQL connection object
Dim ds2 As New DataSet()
Dim da2 As New SqlClient.SqlDa taAdapter()
sqlcmd0.Connect ion = sqlcon
sqlcmd0.Command Text = "select BDCallsMade as 'Calls Made',
BDEmailsSent as 'Emails Sent', activity_ID as ActID, company.company as
'Company Name', date as 'Activity Date', followup as 'Follow Up Date',
notes as Notes, notes_confident ial as Confidential from activity Activity
INNER JOIN Company ON Activity.Client _Company_ID = Company.Company _ID where
(activity_cd = 2 and client_id =" & CurrentID & ") order by date Desc"
da2.SelectComma nd = sqlcmd0
da2.Fill(ds2, "Person")
sqlcon.Close()
DataGrid2.DataS ource = ds2
DataGrid2.DataB ind()
FillTextBoxes(e )
DataGrid2.Visib le = True
Label18.Visible = True
Label18.Text = ds2.Tables("Per son").Rows(0).I tem(0).ToString
Label19.Visible = True
Label19.Text = ds2.Tables("Per son").Rows(0).I tem(1).ToString
Button3.Visible = True
Button4.Visible = True
Label16.Visible = True
Label17.Visible = True
Button3.Enabled = True
Button4.Enabled = True
DataGrid1.Visib le = False
End Sub

And finally, I have a button click event which will update the database.
This is where I need the values of those variables.

Sub UpdateRecord()
Dim cid As String
cid = CurrentID
Dim sqlcmd0 As New SqlClient.SqlCo mmand()
Dim sqlcon = DBConnect()
Dim ds2 As New DataSet()
Dim da2 As New SqlClient.SqlDa taAdapter()
sqlcmd0.Connect ion = sqlcon
sqlcmd0.Command Text = "Update person set name_full = @NameFull
where person_ID =" & cid
End Sub

I am trying to replicate what you showed me as:

Public Class Form1
public myVar1 as integer ' This is outside of an event handler
private sub mySub1() ' My sub is called Datagrid_Select
myVar1 = 1 'CurrentID = e.Item.Cells(11 ).Text.ToString
end sub

private sub mySub2() ' My sub is called UpdateRecord
dim mv as integer ' I dimmed cid
mv = myVar1 ' I set cid = CurrentID
msgbox(mv.tostr ing) ' My code calls for commandtext
end sub
end Class

This is where the variable is "Nothing"

Any ideas where I am going wrong?

Thanks for your help,
Aaron

Nov 20 '05 #7
Hi Aaron,

In this resource kit are a lot of samples, I think that it is good to have a
look for that
,
The problems in your program are in my opinon not on one place and you did
make it direct a little bit complex. Therefore it is in my idea almost
impossible to help you from a newsgroup.

Have a look at those samples for ASP. There is also an asp.net resource kit,
however I think the VB.net one is better. I do the link from the ASP.net
one also beneath these.

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

http://msdn.microsoft.com/asp.net/asprk/

I hope this helps a little bit?

Cor
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3855
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D : byte) ; where A, B are inputs only, and C, D are in/out.
5
2118
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I can get! Consider 3 classes in the following heirarchy: base / \ deriv1 deriv2 \
8
5473
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
16
6141
by: Basil Fawlty | last post by:
Hi everyone, I have an assignment, to create a simple VB program that computes the volume of a cylinder. The Form is pretty simple, it has a label and text box for base radius, another for height and another for volume with an OK button. I have the code to put into the OK button (Which I've done): Private Sub OK_Click( ) --not this line r = Val(radius.Text) --input this line h = Val(hght.Text) --input this...
10
2532
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 TeamScore(1-10) Employee3 TeamScore(1-10) Employee4 TeamScore(1-10) Then I submit this page with all the values in TeamScore for every employee and I want to perform a calculation based on the values in the drop-down and a
1
6085
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name. Please follow the specifications for assignment 3 as described below otherwise points will be taken off. Input from a file Please create an input file named input.txt using a text editor like notepad or the Visual C++ editor and put the following...
8
2742
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't understand why it is doing this. Below is my code, I would be greatfull if someone can guide me through the right path or even help me solve this issue. Problem: The old tool which was written in VB6 works perfect. But I needed to convert this to C#...
19
1954
by: mohammaditraders | last post by:
a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions Cal_percentage() which calculate the percentage of the student by the formula (Ob_marks * 100 ) / Total_marks and Display() which show all information of the student. The class should also contain the default constructor which initializes all the data member of the class. In main program...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9192
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8940
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7781
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.