Code: Select all
dim a(4)
a(0)=1,2,3,4,5
debug a(2)
Code: Select all
dim a(4)
a(0)=1,2,3,4,5
debug a(2)
Done.davido wrote:Just wondering. Could you join the two macros to make data entry simpler?
It shouldn't affect number arrays as there aren't any quotes to convert to double quotes.
Code: Select all
EnableExplicit
Macro CreateArray (_array_, _content_)
Define.i m_jArray = ParseJSON(#PB_Any, ReplaceString("[" + _content_ + "]", "'", #DQUOTE$))
If m_jArray
Dim _array_(0)
ExtractJSONArray(JSONValue(m_jArray), _array_())
FreeJSON(m_jArray)
EndIf
EndMacro
; ===== DEMO =====
Define.i last, i
CreateArray(a.i, "1, 3, 5, 7, 9")
last = ArraySize(a())
For i = 0 To last
Debug a(i)
Next
Debug "-----"
CreateArray(x.d, "1.5, 3.4, 5.3, 7.2, 9.1")
last = ArraySize(x())
For i = 0 To last
Debug StrD(x(i), 1)
Next
Debug "-----"
CreateArray(t$, "'dog', 'cat', 'mouse'")
last = ArraySize(t$())
For i = 0 To last
Debug t$(i)
Next
Anyone particular in mind ? I want names !rsts wrote:Very nice LJ. It's good to have someone who doesn't just talk about how they write good code, but also provides examples.
Code: Select all
Macro MakeArray(name,items)
For i=1 To CountString(items,",")+1
name(i-1)=Val(StringField(items,i,","))
Next
EndMacro
Dim a(4)
MakeArray(a,"0,1,2,3,4")
For n=0 To 4
Debug a(n)
Next
Yes, it would. I can't imagine that doing so could pose any problem.davido wrote:Would it be OK to 'unhinge' the brackets?
Yes, it's not optimized for speed, but for elegance and lazy writing.luis wrote:Brutally inefficient but stylish !
I agree.PB wrote:Short and easy on the eyes/typing:
Code: Select all
; PB 5.22 LTS x86 on Windows
Define s$
Define.q a, b, c
s$ = "9223372036854775100" ; a valid quad number
a = ValD(s$)
b = ValF(s$)
c = Val (s$)
Debug a ; => 9223372036854774784 (wrong)
Debug b ; => -9223372036854775808 (wrong)
Debug c ; => 9223372036854775100 (correct)