Como Obtener En Runtime El Nombre De Una Variable


Subject: Como Obtener En Runtime El Nombre De Una Variable
Es medio tonta la pregunta, pero no lo estoy consiguiendo


por ejemplo

dim fFuerzas as float


Sub miNombre( v1 as float) as string

print v1.name 'imprimo el nombre original del la variable

End sub

miNombre (fFuerzas)

'imprime en la consola fFuerzas


se entiende

Last edited by tercoIDE on Monday, 03 August 2015, 15:27; edited 1 time in total
Profile PM  
Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
Seguramente Vuott sepa alguna manera de sacar ese dato usando punteros.....


Pero se me ocurre una solución fácil:

Create una clase, con la propiedad valor y nombre, entonces es muy sencillo decir que te muestre o cambiar el nombre,.... no se si te servirá...

Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
no me sirve, esta es la rutina real:

Public Sub DebugMe(mf As Float[], filas As Integer, Optional columnas As Integer = 1)
' Rutina para mostrar matrices y vector en el Debug
' para vectores, poner columna=1

Dim f As Integer, c As Integer, stmat As String
'stmat = mf
If columnas = 1 Then
For f = 0 To filas - 1
'modMatriz8.abanda(a, b, a)
stmat &= Format$(mf[f], "0.000000") & " "

Next
Debug stmat
stmat = ""

Else
For f = 0 To filas - 1
For c = 0 To columnas - 1
'modMatriz8.abanda(a, b, a)
stmat &= Format$(mf[f, c], "0.000000") & " "

Next
Debug Str$(f), stmat
stmat = ""

Next

End If
'Stop

End


que sirve para volcar el contenido de una matriz o vector en el debug

me gustaria tambien volcar el nombre de la matriz que estoy debugueando

el workaournd es facil, porque llamo a un

Debug "fMatrix1"
DebugMe(fMatrix1, filas)

y ya, pero queria ver si hay una solucion mas elegante

Profile PM  
Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
jsbsan escribió: [Ver mensaje]
Seguramente Vuott sepa alguna manera de sacar ese dato usando punteros.....


¡No exageremos! Punteros no son el Padre Eterno !

Profile PM  
Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
vuott escribió: [Ver mensaje]


¡No exageremos! Punteros no son el Padre Eterno !



es que vos nos mal acostumbras con tus soluciones eitenianas

260px_albert_einstein_head jajajajja

Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
...bueno...sì, existe una posiblidad usando la Clase "Class", pero la variable debe haber sido declarada "Global" y "Pública" .

Ejemplo pratico:
Public nombre_variable As Integer

Public Sub Main()

' Si el nombre de la variable es compuesto por más que 4 carácteres, entonces el índice es 1 (si hasta 4 el índice es 0) !
Print Class.Load("MMain").Symbols[1]

End

Last edited by vuott on Sunday, 16 August 2015, 16:53; edited 3 times in total
Profile PM  
Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
claro, pero no es el caso


(en octubre estare en Parma, vives cerca?)

Profile PM  
Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
Se necesita preguntar a Minisini en cual Estructura de los codigos fuentes C de gambas es contenido el nombre-identificador de una variable.

Profile PM  
Subject: Re: Como Obtener En Runtime El Nombre De Una Variable
vuott escribió: [Ver mensaje]
¡No exageremos! Punteros no son el Padre Eterno !

......pero... tal vez pueden competir con Él.


Vamos a ver con un Puntero a una variable de tipo String todas las variables locales existentes en un proyecto:

Private Const LAT As Short = 256


Public Sub Main()

Dim s As String
Dim po As Pointer
Dim c As Integer
Dim bb As Byte[]
Dim st As Stream
Dim i As Integer

' Es absolutamente necesario declarar la nuestra imperecedera y inquebrantable fe:
s = "Yo no soy Pythonista !"

po = VarPtr(s)
If po = 0 Then Error.Raise("Puntero no valido !")

st = Memory po For Read

With bb = New Byte[LAT]
.Read(st, 0, bb.Count)
s = .ToString(0, bb.Count)
End With
st.Close

c = InStr(s, Chr(&40) & Chr(&6E) & Chr(&65))

s = bb.ToString(c + 4, InStr(s, "\x00\x00", c) - (c + 4))

Print Replace(s, "\x00", "\n")

End


Private Procedure Nomen(b As Byte)

Dim sh As Short
Dim n As Integer
Dim v As Variant

End

Last edited by vuott on Monday, 04 April 2016, 23:08; edited 3 times in total
Profile PM  

Page 1 of 1


  
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo

Generation Time: 0.1175s (PHP: -4% SQL: 104%)
SQL queries: 26 - Debug Off - GZIP Enabled