Professional Documents
Culture Documents
Converting Visual Basic 6 Source Code To B4A
Converting Visual Basic 6 Source Code To B4A
VB6
B4A
3.
===
===
4. controls
Views
5. In the VB6 code window, the top left drop-down list contains all
6. the controls you have placed in the current form and the right list
7. contains all the events for each control.
can
11.
12.
13.
14.
15.
editBox = string
editBox.Text = string
16.
In VB6, you can leave ".Text" off the names of controls when
assigning
17.
18.
19.
Dim/ReDim:
20.
---------
21.
Dim Array(n)
Dim Array(n+1)
22.
23.
24.
with 0-32 elements in VB6, you would say Dim A(32), while to
convert
25.
26.
27.
ReDim Preserve
28.
ReDim Array()
Dim it again.
Use a List.
Dim Array(n+1) -- to clear an array, just
29.
30.
If Not b Then...
If Not(b) Then...
31.
If b Then...
same
32.
If b = True Then
same
33.
If a Then...
If a > 0 Then...
34.
35.
a = a + b
36.
If b = True Then a = a - 1
Boolean's value cannot be used in a
38.
Dim x as
Int: x = 1
39.
40.
41.
42.
---------------------------
43.
Do [Until/While]
same
44.
Loop [Until/While]
Loop
45.
For - Next
same
46.
Exit Do/For
Exit
Next.
47.
48.
If - Then - Else
B4A; ditto EndIf
49.
50.
--For i = 1 to 6
51.
If i <> 4 Then
52.
...code...
53.
End If
54.
Next
55.
56.
57.
Colors:
58.
------
59.
L1.BackColor =
60.
vbRed
61.
L1.ForeColor =
62.
vbBlack
L1.Color = Colors.Red
L1.TextColor = Colors.Black
63.
64.
Calling a sub:
65.
-------------
66.
SubName x, y
SubName(x, y)
67.
Sub SubName()
Sub SubName() As Int/String/etc. -- a
Global variable cannot be
68.
69.
70.
71.
i=player: PlayCard(i)
Function FName()
As [var.type]
Function by adding a
72.
73.
74.
75.
...optional code...
76.
77.
78.
...optional code...
End Sub
79.
80.
81.
82.
so is just "CheckX(x)"
83.
Exit Sub
Return
84.
Exit Function
Return [value]
85.
86.
General:
87.
-------
88.
CInt
89.
DoEvents
90.
92.
93.
94.
95.
96.
97.
98.
99.
Format()
documentation]
100.
InputBox($)
InputList(Items as List, Title,
CheckedItem as Int) as Int
101.
can list multiple
buttons. Returns index.
102.
103.
List
104.
number to choose.
checkboxes.
105.
boxes checked.
106.
MsgBox "text"
107.
i=MsgBox()
Negative, Icon) as Int
108.
display for buttons
109.
MsgBox("text", "title")
MsgBox2(Message, Title, Positive, Cancel,
110.
is specified like:
111.
"[filename].gif")
LoadBitmap(File.DirAssets,
112.
--for long duration]
113.
114.
Sub InputBox(Prompt As String, Title As String, Default As
String, Hint As String) As String
115.
Dim Id As InputDialog
116.
Id.Hint = Hint
117.
Id.Input = Default
118.
119.
120.
End Sub
121.
122.
Rnd is < 1
123.
Rnd(-#)
RndSeed(#) - causes Rnd to generate the
same random number series
124.
125.
126.
Round(n)
decimal places
127.
128.
i = Val(string)
i = 0 --
129.
An attempt to use i=string "throws an
exception" if the string is
130.
not numbers, even if the string starts
with numbers. For example,
131.
t = "10:45"
132.
in B4A.
133.
Instead,
134.
i = t.SubString2(0, 2) = 10
135.
control.SetFocus
136.
n / 0 : error
an exception" for
view.RequestFocus
n / 0 = 2147483647 -- B4A does not "throw
137.
2147483647 no matter
138.
139.
x = Shell("...")
replacement, but allows
140.
B4A forum (by Erel):
141.
Dim pi As PhoneIntents
142.
StartActivity
(pi.OpenBrowser("file:///sdcard/yourfile.html"))
143.
t = Timer
t = DateTime.Now ' Ticks are number of
milliseconds since 1-1-70
144.
145.
TabIndex:
146.
--------
147.
In VB6, TabIndex can be set to control the order in which
controls get focus
148.
149.
"Android handles the sequence according to their position.
You can set
150.
EditText.ForceDone = True in all your EditTexts. Then
catch the
151.
EditText_EnterPressed event and explicitly set the focus
to the next
152.
153.
154.
155.
--------------------------
156.
157.
158.
Constants:
159.
---------
160.
""
Quote = Chr$(34)
161.
vbCr
CRLF = Chr$(10)
162.
vbCrLf
none
163.
164.
String "Members":
165.
----------------
166.
167.
168.
VB6
B4A
169.
Mid$("abcde", 1, 1) = "a" = letter array index 0 -- "a" =
"abcde".CharAt(0)
170.
171.
172.
173.
174.
VB6
B4A
175.
===
===
176.
Mid$(text, n, 1)
text.CharAt(n-1)
177.
Mid$(text, n)
text.SubString(n-1)
178.
Mid$(text, n, x) [x=length wanted]
1) [n+x-1=end position]
text.SubString2(n-1, n+x-
179.
Mid$(text, n, x) = text2
n-2) & _
text = text.SubString2(0,
180.
text2.SubString2(0, x-1) & _
181.
+ z)
text.SubString(n-1
where...
182.
text2.length)
183.
Left$(text, n)
z = Min(x,
[n=num.of chars.]
text.SubString2(0, n)
184.
Right$(text, n)
text.SubString(text.Length - n + 1)
185.
If a$ = b$...
If a.CompareTo(b)...
186.
If Right$(text, n) = text2...
text.EndsWith(text2)...
If
187.
If Left$(text, n) = text2...
text.StartsWith(text2)...
If
188.
If Lcase$(text) = Lcase$(text2)...
text.EqualsIgnoreCase(text2)...
If
189.
Following are some subs from NeoTechni which take the place
of VB6
190.
string functions:
191.
192.
193.
194.
End Sub
195.
196.
197.
Return text.SubString(text.Length-length)
198.
End Sub
199.
Sub Mid(Text As String, Start As Int, Length As Int) As
String
200.
Return text.SubString2(start-1,start+length-1)
201.
End Sub
202.
203.
204.
Return Regex.Split(delimter,text)
End Sub
205.
206.
x = Len(text)
x = text.Length
207.
text.Replace(str, str2)
208.
Lcase(text)
text.ToLowerCase
209.
Ucase(text)
text.ToUpperCase
210.
Trim(text)
text.Trim
211.
212.
text.IndexOf(string)
213.
int)
text.IndexOf2(string,
214.
found.
Returns -1 if not
215.
not position.
216.
"int".
Starts search at
217.
218.
start)
text.LastIndexOf(string)
text.LastIndexOf(string,
219.
optionally from "start".
sensitivity.
220.
case = 0 = case-sensitive
221.
case = 0 = case-insensitive
222.
is -
223.
= True Then...
If text.Contains(string)
224.
If Lcase$(x) = Lcase$(y)...
x.EqualsIgnoreCase(y)...
If
225.
text.Insert(n, s)
226.
227.
228.
229.
Error Trapping:
230.
--------------
same
231.
VB6:
232.
===
233.
Sub SomeSub
234.
235.
...some code...
236.
237.
238.
239.
ErrorTrap:
240.
241.
242.
End Sub
243.
B4A:
244.
===
245.
Sub SomeSub
246.
247.
Try
...some code...
248.
249.
Log(LastException) [optional]
250.
251.
End Try
252.
253.
End Sub
254.
WIth B4A, if you get an error caught in the middle of a large
subroutine, you can
255.
NOT make a correction and resume within the code you were
executing. Only the code
256.
257.
258.
--------------------------
259.
Try-Catch can be used as a substitute for GoTo [line label]
for forward, but not
260.
backward, jumps. It cannot be used to replace GoSub, for
which B4A has no equivalent.
261.
Start the code with "Try" and replace the [line label] with
"Catch".
262.
Replace "GoTo [line label]" with code which will create an
exception, which causes
263.
a jump to "Catch", such as OpenInput("bad path", "bad
filename").
264.
265.
266.
--------------------------------
267.
Comments, variable values, etc., can be displayed in VB6's
Immediate
268.
269.
In the B4A environment, the Logs tab on the right side of the
IDE is a
270.
way to show the values of variables, etc., while the code is
running.
271.
Both VB6 and (now) B4A allow single-stepping through the code
while it
272.
is running and viewing the values of variables. VB6 also
allows changing
273.
the value of variables, changing the code, jumping to other
lines from
274.
the current line, etc. Because B4A runs on a PC while the app
runs on
275.
a separate device, B4A is currently unable to duplicate all
of these
276.
http://leandroascierto.com/foro/index.php?topic=1350.0