variable question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey all,

Given:
strVal1 = array.getvalue(0)


Is there a way I can have a variable in place of strVal1 that will point to
strVal1. I guess what I'm asking is if there's a way to make a variable point
to another variable?

Also, please give any opinions about this.

thanks,
rodchar
 
rodchar said:
Given:
strVal1 = array.getvalue(0)

Is there a way I can have a variable in place of strVal1 that
will point to strVal1. I guess what I'm asking is if there's a
way to make a variable point to another variable?

Why? You can reference /objects/, which are instances of classes, not
variables.
 
rodchar said:
Hey all,

Given:
strVal1 = array.getvalue(0)


Is there a way I can have a variable in place of strVal1 that will point to
strVal1. I guess what I'm asking is if there's a way to make a variable point
to another variable?

Can you give a more spesific context to this problem?


If strVal is private inside a class, then you can use a Property to referance to it from the oustide.


class myclass
private strVal as String

public property myVal as string
get
'some other code here perhaps...
return strVal
end get
set (Value as String)
if Value.Length >0 then strVal = Value
end set
end property
end class

From the outside you will se this as myclass.myVal

Dim m as new myclass
m.myVal = "hello world"
Dim s as string = m.myVal

You can even have ReadOnly or WriteOnly Properties, that can only be read or written to. The example above you can do both.
 
I'm trying to see if there's a way to streamline the following:

Dim eeCode, eeRate, erCode, erRate As String
Dim tb As TextBox

tb = CType(e.Item.Cells(1).Controls(0), TextBox)
eeCode = tb.Text
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
eeRate = tb.Text
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
erCode = tb.Text
tb = CType(e.Item.Cells(4).Controls(0), TextBox)
erRate = tb.Text
 
rodchar said:
I'm trying to see if there's a way to streamline the following:

Dim eeCode, eeRate, erCode, erRate As String
Dim tb As TextBox

tb = CType(e.Item.Cells(1).Controls(0), TextBox)
eeCode = tb.Text
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
eeRate = tb.Text
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
erCode = tb.Text
tb = CType(e.Item.Cells(4).Controls(0), TextBox)
erRate = tb.Text


Not much, because you're using separate variables for the
different strings. (eeCode, ccRate ...) Had you made them
an array of strings, you could fill it within a loop. (if, for
example, you were filling up to 15 or 20 such strings, a loop
would add a significant reduction)

Even if you want to keep individual variables, you can remove
some of that code because VB will let you initialize variables
as you declare them, such as:

Dim eeCode As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim eeRate As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
.... etc ...

Using a With block you could remove even more:

With e.Item
Dim eeCode As String = CType(.Cells(1).Controls(0), TextBox).Text
Dim eeRate As String = CType(.Cells(2).Controls(0), TextBox).Text
.... etc ...
End With

But (with separate variables) that is about as far as you can go.

HTH
LFS
 
thank you very much, i'll take it.

Larry Serflaten said:
Not much, because you're using separate variables for the
different strings. (eeCode, ccRate ...) Had you made them
an array of strings, you could fill it within a loop. (if, for
example, you were filling up to 15 or 20 such strings, a loop
would add a significant reduction)

Even if you want to keep individual variables, you can remove
some of that code because VB will let you initialize variables
as you declare them, such as:

Dim eeCode As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim eeRate As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
.... etc ...

Using a With block you could remove even more:

With e.Item
Dim eeCode As String = CType(.Cells(1).Controls(0), TextBox).Text
Dim eeRate As String = CType(.Cells(2).Controls(0), TextBox).Text
.... etc ...
End With

But (with separate variables) that is about as far as you can go.

HTH
LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top