Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can some body please explain me that what is mean by unused local variable and how we have to create it for exam i have a coding in that the Waring message came to me that unused local variable

Dim sub1(HERE IT SHOW ME THAT UNUSED LOCAL VARIABLE) As String
           OleDbConnection1.Open()
           Dim str As String
           str = "select brrelno from submaster where subcode=@subcode"
               Dim cmd As OleDbCommand
               Dim cmd1 As OleDbCommand
           cmd = New OleDbCommand(str, OleDbConnection1)
               cmd.Parameters.AddWithValue("@subcode", Application("subcode"))
           res = cmd.ExecuteScalar
           cmd.Connection.Close()


What I have tried:

what that its mean and please tell that how to clear this problem
Posted
Updated 22-Jan-20 0:36am
Comments
Richard MacCutchan 22-Jan-20 3:59am    
Whatever variable you have declared in the sub1 definition (where you have written: "HERE IT SHOW ME THAT UNUSED LOCAL VARIABLE"), is never referenced in the following code.

Quote:
can some body please explain me that what is mean by unused local variable

May be it is this unused variable:
VB
Dim sub1(HERE IT SHOW ME THAT UNUSED LOCAL VARIABLE) As String
           OleDbConnection1.Open()
           Dim str As String
           str = "select brrelno from submaster where subcode=@subcode"
           Dim cmd As OleDbCommand
           Dim cmd1 As OleDbCommand
           cmd = New OleDbCommand(str, OleDbConnection1)
           cmd.Parameters.AddWithValue("@subcode", Application("subcode"))
           res = cmd.ExecuteScalar
           cmd.Connection.Close()
 
Share this answer
 
Please post the actual contents of:
Dim sub1(HERE IT SHOW ME THAT UNUSED LOCAL VARIABLE) As String

My thought is you are defining a variable in this location, that you are not using.
 
Share this answer
 
Probably you are trying to use a variable which you did not define yet (or trying to use a local variable to a function which has become inaccessible outside of its function).
VB
Dim count As Integer = 42
Dim sub1(count) As String '' Will work and define a string array with 42 elements
Dim sub2(unknown) As String '' Will raise an error when unknown variable is used

Your naming is ambiguous, though. You may as well want to define a function, but functions are not defined with Dim keyword:
VB
Public Function sub1(ByVal variable As Integer) As String
   '' ...
End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900