What is the reason of an error "Array access, index expected" - freebasic

I get an error 73 "Array access..." with code:
#include "args.bas"
Dim aargs(1) As Args.Arg
Dim args_num As Integer = 0
args_num = Args.ParseArgs(aargs) 'error 73: Array access, index expected, before ')' in 'args_num = Args.ParseArgs(aargs)'
Print args_num
ParseArgs is:
#pragma once
Namespace Args
...
Type CommandGetter As Function(ByVal arg_idx As Long) As String
Function ParseArgs(aargs(Any) As Arg, getcmd As CommandGetter=NULL) As Integer
...
End Function
End Namespace
What's wrong here?

Stupid question :)
Passing of arrays needs (), the correct syntax is:
args_num = Args.ParseArgs(aargs())

Related

`+': no implicit conversion of Integer into String (TypeError)

Getting this error:
(`+': no implicit conversion of Integer into String (TypeError))
This is the line calling it:
print "\tsize "+(package["size"] == nil ? "" : package["size"])+"\n";
When package["size"] is not nil, its returning and integer and you're trying to concatenate it into a string, and its not doing implicite typcasting of values
Here are a few ways you can get it to work
Solution 1.
"\tsize " + package['size'].to_s + "\n";
Solution 2.
"\tsize #{package['size'].to_s}\n";

Get variable type (ADO Object or String) in ASP Classic?

I'm trying to write a function in ASP Classic that accepts a parameter; but the parameter can either be a String, or an ADODB.Command Object. How can the function determine which type the parameter is?
So...
Function myfunction( input )
If is_ADODBCommand( input ) Then
' do stuff to object'
ElseIf is_string( input ) Then
' do stuff to string'
End If
End Function
Basically, please tell me how to do is_ADODBCommand and is_string
You can use VarType for primitive types.
is_string = (VarType(input) = vbString)
For object types, you can use TypeName since VarType returns a generic type specifier vbObject which gives no clue about the object's kind.
is_ADODBCommand = (TypeName(input) = "Command")

VBS running code from string

I have one string storing hexadecimal data (\xEA\x...). Is it anyway to run that code using vbs? Maybe doing some kind of casting to function pointer or similar.
The C version of what I'm trying to do would be:
unsigned char opcode[] = "\xc0\x...."
main()
{
int (*run)() = (int(*)())opcode;
run();
}
Thank you so much.
You can use function pointers (or function references) with the GetRef function:
dim fp : set fp = GetRef("ShowMessage")
call fp("Woosh")
function ShowMessage(msg)
msgbox msg
end function
To make this work for any string with normally illegal characters for function naming (like the backslash in hexadecimal data) you can use brackets in you function declaration:
dim fp : set fp = GetRef("99 problems")
call fp()
' note: functions normally cannot start with a digit or contain spaces
function [99 problems]()
msgbox "but this aint one"
end function
The only character you cannot use is a closing bracket: ]

Runtime Error 424 Object Required in Vb6

I am new to Vb,
i am getting error in my source code,
here is my code snippet,
Dim a,b as integer
a=val (txtf.Text)
b=val (txts.Text)
if(a>b)then
txtr=a
else
txtr=b
end if
end sub
ERROR: Runtime Error 424 Object Required:
any help will be appriciated.
It is safer to type
Dim a as Integer
Dim b as integer
or
Dim a as integer,b as integer
This might be the case of the error
You haven't defined textr . Do that and your prob will be solved.
You did not specify txtr as txtr.txt instead it read txtr as an object...
Error that I found You should separate a,b; instead write is as:
Dim a as integer,b as integer or
Dim a as integer
Dim b as integer

VB6: How to pass temporary to a function in Visual Basic 6

In C++ it is possible to pass a temporary object argument to a function:
struct Foo
{
Foo(int arg);
// ...
}
void PrintFoo(const Foo& f);
PrintFoo(Foo(10))
I am trying to implement something similar in Visual Basic 6:
'# Scroll bar params
Public Type ScrollParams
sbPos As Long
sbMin As Long
sbMax As Long
End Type
Public Function MakeScrollParams(pos As Long, min As Long, max As Long)
Dim params As ScrollParams
With params
.sbPos = pos
.sbMin = min
.sbMax = max
End With
Set MakeScrollParams = params
End Function
'# Set Scroll bar parameters
Public Sub SetScrollParams(sbType As Long, sbParams As ScrollParams)
Dim hWnd As Long
' ...
End Sub
However, Call SetScrollParams(sbHorizontal, MakeScrollParams(3, 0, 10)) raises an error: ByRef argument type mismatch. Why?
A couple of things need to change from your existing code:
You need to strongly-type the declaration of the MakeScrollParams function.
It returns an instance of the ScrollParams type, so you should specify that explicitly in the declaration. Like so:
Public Function MakeScrollParams(pos As Long, min As Long, max As Long) As ScrollParams
You need to remove the Set keyword from the last line in that function in order to avoid an "Object Required" compilation error. You can only use Set with objects, such as instances of classes. For regular value types, you omit it altogether:
MakeScrollParams = params
So the full function declaration would look like this:
Public Function MakeScrollParams(pos As Long, min As Long, max As Long) As ScrollParams
Dim params As ScrollParams
With params
.sbPos = pos
.sbMin = min
.sbMax = max
End With
MakeScrollParams = params
End Function
And calling it like this:
Call SetScrollParams(sbHorizontal, MakeScrollParams(3, 0, 10))
now works perfectly.
Maybe?
Public Function MakeScrollParams(pos As Long, min As Long, max As Long) As ScrollParams

Resources