Owner Info help needed

kshetarpal

Member
Licensed User
Hi,
I am a new user of Basic4PPC. I tried the following code to get ownerinfo based on a code sample. Upon compiling I get nothing. Obviously, I am doing something wrong here.
Here is the code:

Sub Globals
Dim buff(0) As Byte
End Sub

Sub App_Start
Reg.New1 'Registry object is named 'reg'
Form1.Show
End Sub


Sub Button1_Click
If CPPC = false Then Return 'this is not for the desktop
Dim m
Reg.RootKey(Reg.rtCurrentUser)
buff() =Reg.GetValue("ControlPanel\Owner\","Owner")
For i = 0 To ArrayLen(buff()) -1 Step 2
If buff(i)=0 Then Exit 'Chr(0) separates the name from other owner entries
m = m & Chr(buff(i))
Next
Return m
Msgbox ("Owner name ",m)
TextBox1.Text= m
End Sub

Sub Button2_Click
AppClose
End Sub

I would appreciate the corrections of the code.

Amit Kshetarpal
 

colin9876

Active Member
Licensed User
hi, I might be wrong....
1)But can u just Dim m like that? dont u have to do it in the Globals area and define how many elements the array has in it?
also
2) you've Dim-ed Buff as (0) bytes long - THATS NO LENGTH? wont u need it long enough to store the name?? {Or does Dim buff(0) mean it can be any length?}

(if Im wrong on the above points please correct me, cos Im a newbie?)
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Remove 'Return m' if you want the msgbox to appear, and the TextBox be assigned.
Return leaves the sub immediately.
1)But can u just Dim m like that? dont u have to do it in the Globals area and define how many elements the array has in it?
also
2) you've Dim-ed Buff as (0) bytes long - THATS NO LENGTH? wont u need it long enough to store the name?? {Or does Dim buff(0) mean it can be any length?}
1) Dim m is equivalent to m = "".
It is absolutely legal to use it. The result will be a local variable.
If it were declared under Sub Globals then it would have been a global variable.
See this topic for more information: http://www.basic4ppc.com/help/variables.html
2) You can declare an empty array.
Later you will need to redimension it with another dim or (in this case) call a function that returns an array.
B4X:
buff() =Reg.GetValue("ControlPanel\Owner\","Owner")
Reg.GetValue returns an array of bytes.
Using ArrayLen you can find the size of the array returned.
 
Top