jadaoradix
New member
- Joined
- Jun 19, 2011
- Messages
- 2
- Programming Experience
- 5-10
I would like to do something like this:
So that we can use logic to determine the variable to change. This is to avoid using two Select-cases, as per my actual code:
You ask - why not put the variable setting code in the first select-case (combine branches)? Not possible. The code to determine the value to set, is generic and happens after the first select case. Then the variable is set. You'd have to copy that code into each branch.
I don't see any way to do it, than to have a pointer variable that can be set to the memory of a variable. I already use Delegates for functions; my .NET code is going to get really ugly, repetitive and inefficient if there's no way to use pointers like my first example.
Thanks.
VB.NET:
Dim GenericData as String = "Hello, World"
Dim FirstName as String = "Daniel"
Dim LastName as String = "Gero"
Dim ToChange as VariablePointer 'pseudo
If ChangeFirstName
ToChange = MemoryOf FirstName
MsgBox("Changed first name!")
Else
ToChange = MemoryOf LastName
MsgBox("Changed last name!")
End If
ToChange = GenericData
So that we can use logic to determine the variable to change. This is to avoid using two Select-cases, as per my actual code:
VB.NET:
Sub GMImport()
Dim Magic As Int16 = 0
Dim Version As Int16 = 0
Dim Data() As Byte = File.ReadAllBytes(ImportData)
Dim Pos As UInt64 = 0
While Pos < Data.Length
Dim BytesToTravel As UInt16 = 4
'FIRST select case here ::
If Pos = 0 Then
BytesToTravel = 4
ElseIf (Pos + 1) = 4 Then
BytesToTravel = 4
End If
Dim SubBytes(BytesToTravel) As Byte
For G As Int16 = 0 To BytesToTravel
SubBytes(G) = Data(Pos + G)
Next
Dim Final As Int16 = BitConverter.ToInt16(SubBytes, 0)
'ANOTHER SELECT CASE HERE, to determine which variable to change.
'ANNOYING because these select cases will get very long and there will be two of them.
If Pos = 0 Then
Magic = Final
ElseIf (Pos + 1) = 4 Then
Version = Final
End If
MsgError(Pos.ToString + ": " + Final.ToString)
Pos += BytesToTravel
End While
End Sub
You ask - why not put the variable setting code in the first select-case (combine branches)? Not possible. The code to determine the value to set, is generic and happens after the first select case. Then the variable is set. You'd have to copy that code into each branch.
I don't see any way to do it, than to have a pointer variable that can be set to the memory of a variable. I already use Delegates for functions; my .NET code is going to get really ugly, repetitive and inefficient if there's no way to use pointers like my first example.
Thanks.