1. mahmoud mahmoud
  2. PowerBuilder
  3. Friday, 18 November 2022 19:58 PM UTC

PowerBuilder string value to int array

i need ►

◄ ls_value2

convert to ►

◄ noa_payment[]

 

//========need=========
//noa_payment[] = ls_value2

String ls_data[], ls_value, ls_cln 
int noa_payment[]

ll_col = dw_3.getcolumn()
ls_cln =  dw_3.Describe("#" + String(ll_col)  + ".name")

ll_count = invo_dddw_multiselect.of_getdata(ls_cln  , dw_3.GetRow(), ls_data)


ls_value2=""
For ll_row = 1 To ll_count
	ls_value2 += ls_data[ll_row] + ","
	
Next

//========need=========
//noa_payment[] = ls_value2 
Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Saturday, 19 November 2022 20:18 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi,

 

Is this what you're looking for?

string ls_value2= "1,2,3,4,5,6,77,888"
integer noa_payment[] // Like Olan said, you might have to use a Long instead of Integer if the values are bigger than integers?
long ll_start, ll_end, ll_i
string ls_temp

// make sure the string ends on a "," since that's what we are going to look for until there's none left:
// (though, when looking at your other code, it already does end on a ",").
if right(ls_value2, 1) <> "," then
	ls_value2 += ","
end if

ll_start = 1
ll_end = pos(ls_value2, ",")

do while ll_end > 0 
	ls_temp = mid(ls_value2, ll_start, ll_end - ll_start)
	
	ll_i ++
	// if you decide to use a Long instead of Integer, do this:
	// noa_payment[ll_i] = Long(ls_temp)
	// but for now, you are using an integer array, so ...:
	noa_payment[ll_i] = Integer(ls_temp)
	
	ll_start = ll_end + 1
	ll_end = pos(ls_value2, ",", ll_start)
loop

// show the integer values:
for ll_i = 1 to UpperBound(noa_payment)
	messagebox('debug', noa_payment[ll_i] )
next
Comment
  1. Miguel Leeuwe
  2. Saturday, 19 November 2022 20:43 PM UTC
What I don't really understand is why you first want to put all the values in "ls_value2". Instead, you could just directly put the values in "noa_payment[]":

// code:

For ll_row = 1 To ll_count

noa_payment[ll_row] = Integer( ls_data[ll_row] )

Next

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 18 November 2022 20:10 PM UTC
  2. PowerBuilder
  3. # 1

noa_payment [???? ] = Integer ( ls_value2 )  // where ??? = array variable

Comment
  1. Olan Knight
  2. Friday, 18 November 2022 22:47 PM UTC
FYI: As a rule I use LONG values, not integers unless the smaller variable is required.
  1. Helpful
  1. Miguel Leeuwe
  2. Saturday, 19 November 2022 20:51 PM UTC
Hi Olan,

I don't know exactly when, but long time ago, someone told me that all Integer variables are "internally" converted to long variables anyway by the interpreter. The only function they have is to set boundaries and manage overflows.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Saturday, 19 November 2022 20:58 PM UTC
No, not in general. However, that "might" occur during a calculation within a formula of other data types. ;-)
  1. Helpful
There are no comments made yet.
mahmoud mahmoud Accepted Answer Pending Moderation
  1. Saturday, 19 November 2022 19:05 PM UTC
  2. PowerBuilder
  3. # 2

please help

i have value string

and i have integer array

i need the value in string variable transfer to integer array

 

when i wrote this code it work with 1 number like 1 or 3 but 1,2,3 not working

string ls_value2= "1,2,3"
integer noa_payment[]


//=======need=======
noa_payment[] ={integer(ls_value2)}
Comment
  1. Miguel Leeuwe
  2. Saturday, 19 November 2022 20:19 PM UTC
See my answer below.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.