Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) writing different datatypes in array (Read 2093 times)
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
writing different datatypes in array
Mar 27th, 2006 at 12:26am
Print Post Print Post  
hi

i try to write values with different data types into a String Array

i tried
1)    Array[1,1] = @Str(variable)
2)    SetStringElement(variable,Array,1,1)
3)    t1 = @Str(variable)         (t1 as string)
      Array[1,1] = t1

and a lot combinations and variations of this codes
and also some really strange codes

pleas help me i am working since hours on that
  
Back to top
ICQ ICQ  
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: writing different datatypes in array
Reply #1 - Mar 27th, 2006 at 12:32am
Print Post Print Post  
You are clearly aware that you will need to convert non-string types to string before assigning them to the array.

What problem are you seeing?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #2 - Mar 27th, 2006 at 12:38am
Print Post Print Post  
its clear that i have to convert

but when i type suche codes like above i get one time

Runtime type mismatch while accessing an array.

and in other cases a windows errors
  
Back to top
ICQ ICQ  
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #3 - Mar 27th, 2006 at 12:39am
Print Post Print Post  
there are double, int, string and date formats in code
  
Back to top
ICQ ICQ  
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: writing different datatypes in array
Reply #4 - Mar 27th, 2006 at 12:58am
Print Post Print Post  
Sesame's SBasic is type strict. That means that you have to convert to correct data type (string) when going into the array, and then convert back to the correct type (string, double, int, date, etc...) when data is moved back out of the array.

For example lets say you have:
Code
Select All
var aa as int
var aa as double
var ab as string

  aa = 10.4

  // convert aa to string
  ab = @Str(aa)

  // put it back - converting it back into a number
  aa = @ToNumber(ab)
 



To do this with a large or complicated array, you will have to store the original types either with a second parallel array, or by position (the fourth element is always a date..., etc) within the original array.

if you are getting this:
Quote:
Runtime type mismatch while accessing an array.


That means that you are trying to use the array as though the elements in it are not string. When using the array, before converting it back to numeric types, you cannot (for example) divide, subtract, or multiply - such operations are meaningless on strings.

Code
Select All
  aa = @ToNumber(a_array[1, 1])
  ab = @ToNumber(a_array[1, 2])
  ac = aa * ab
  a_array[1, 3] = @Str(ac)
 





 
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #5 - Mar 27th, 2006 at 1:13am
Print Post Print Post  
Code
Select All
ab = @Str(aa) 


i used this in the way
Code
Select All
vEPrice_N as double
vEprice_N = 1.443

ArtikelArray[1,1] = @Str(vEPrice_N)
Writeln(ArtikelArray[1,1])
 


if i type in this code i get only the 1 back
the aftercomma is not in it



could an other failiture be that we use in europe a " , " instad of a " . "

  
Back to top
ICQ ICQ  
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: writing different datatypes in array
Reply #6 - Mar 27th, 2006 at 1:20am
Print Post Print Post  
Quote:
could an other failiture be that we use in europe a " , " instad of a " . "


Not too likely, the author of SBasic is Andreas Goebels of Germany (also the author of Q&A 5.0) - but I'll look into it.

Try it with a period and see how it does - then double check your locale settings.

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #7 - Mar 27th, 2006 at 1:36am
Print Post Print Post  
i tried it with the following code and it worked
now i will try it in the whole programm to implement

Code
Select All
var ArtikelArray as array[10,10] of String
var Preis as double
var p1 as double
var p2 as double
var p3 as date


p1 = 2
p2 = 3
p3 = @date

Preis = p1/p2


ArtikelArray[1,1]=@Str(preis)
ArtikelArray[1,2]=@Str(p3)
writeln(ArtikelArray[1,1])
writeln(ArtikelArray[1,2])
 



mybe there is an other error in my code that i have to locate

  
Back to top
ICQ ICQ  
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #8 - Mar 27th, 2006 at 2:36am
Print Post Print Post  
it is realy realy confusing

one time it works then i put in new code (same code as the line before ) and it does not work
if i delete the new code and save it to a new file the error occures again (same code which worked before)

Errors:
Quote:
Runtype missmatch while accessing an array.

this is followed by
Quote:
Error: A runtime SBasic error has occured. Please close this form and repair the condition before continuing.


some times comes a windows Error which is like this one but translated by me into english

Quote:
The command in "0x0054604a" recommits on storage in "0x62736766". The command "read" could not be performed on the storage.


i canceld out a lot of code but with no effect

is it possible that there is too much code in the program??
  
Back to top
ICQ ICQ  
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: writing different datatypes in array
Reply #9 - Mar 27th, 2006 at 2:45am
Print Post Print Post  
It is unlikely that there is too much code. (How much do you have?)

It is more likely that once this:
Quote:
Runtype missmatch while accessing an array.


happens, further problems cascade due to the runtime error.

Check the code for accesses to the array and make sure that in every case the types are correct for the operation. Fill your code with debug writeln statements to help you narrow down which line is causing the runtime error.

Also, if you are passing the entire array into any user defined functions or subroutines, make sure you are using the appropriate access methods.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #10 - Mar 27th, 2006 at 2:57am
Print Post Print Post  
the whole program has about 5000 lines

i only put in what i wrote before

the variables are already decleared so i just write in one line (ArtikelArray[1,1]=@str(variable) )
and for control the line writeln(ArtikelArray[1,1])

sometime this work

but if i add direct below (ArtikelArray[2,1]=@str(variable2)) this never work

Quote:
happens, further problems cascade due to the runtime error.

no there are no other problems it runs perfect

but a bit slow becaus of subform accssess in a loop so i wanted to built a array to get the thing faster

  
Back to top
ICQ ICQ  
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: writing different datatypes in array
Reply #11 - Mar 27th, 2006 at 3:12am
Print Post Print Post  
Quote:
the whole program has about 5000 lines

Is that in one event, or spread across many events. How much code is in the event with the most code, in kilobytes?
Quote:
i only put in what i wrote before

the variables are already decleared so i just write in one line (ArtikelArray[1,1]=@str(variable) )
and for control the line writeln(ArtikelArray[1,1])

sometime this work

but if i add direct below (ArtikelArray[2,1]=@str(variable2)) this never work

no there are no other problems it runs perfect

I meant that after you see the first error, it is the likely cause of the next two errors you reported.
Quote:
but a bit slow becaus of subform accssess in a loop so i wanted to built a array to get the thing faster

If you still have the subform, you will need to access the subform to fill your array. If that is the case, you do not need the array - just make sure that you only access each subform record/row once, reading the data into individual variables, then operate on those variables as needed, then feed them back into the subform record/row once. That approach will actually give you the highest performance, even faster (and easier) than using an array, because there is no need to index individual variables.

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: writing different datatypes in array
Reply #12 - Mar 27th, 2006 at 3:21am
Print Post Print Post  
What version of Sesame are you using?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #13 - Mar 27th, 2006 at 3:33am
Print Post Print Post  
Quote:
Is that in one event, or spread across many events. How much code is in the event with the most code, in kilobytes?


it is spread over about 50 LEs
most code about 700 lines in one LE (Printing) about 17KB

global code about 600 lines

Quote:
If you still have the subform, you will need to access the subform to fill your array.


it is a program which is used for selling (POS) like in a super market but a smaller shop

so i write the data to the subform for storing
i use the array for calculating the end price and some else things and there the array is much faster.
so i want to write the data to the subform and to the array

Quote:
just make sure that you only access each subform record/row once,

i will take a look on it to be really sure

Quote:
reading the data into individual variables

is a alternative idea what to think about


will work on it tomorrow have to go on work in 2 hours and need some sleep
  
Back to top
ICQ ICQ  
IP Logged
 
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
Re: writing different datatypes in array
Reply #14 - Apr 12th, 2006 at 3:56pm
Print Post Print Post  
Some questions after successful programming:

Why is it not possible to handle Arrays defined in global code in a subroutine like this:

Code
Select All
var tempArray as Array[10] of string

subroutine test
tempArray[1] = "xy"
end subroutine

test()

  



i managed this with the following code

Code
Select All
[b]stat[/b] tempArray as Array[10] of string

subroutine test
tempArray[1] = "xy"
end subroutine

test()

  



next question:

why is it not possible to use generic arrays on stat arrays like this:

Code
Select All
stat tempArray as Array[10] of string

subroutine test (var arrayIn as array)

SetStringElement("xy",arrayIn,1)
end subroutine

test(tempArray)

 



and an other question:

i just tried to use the split command in a while loop and this does not work

Code
Select All
i = 10
j = 1

While j <= i
{
	   vLine = ArrayTemp[j]

	   while k < 19
	   {
	LSArray[k,j] = Split(vLine,"$")
	k = k + 1

	   }
j = j + 1
}
 



if anyone has a idea pleas tell me

sebastian
  
Back to top
ICQ ICQ  
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print