Page 1 of 1

How to fix my code? comments turns to be equal to each other?

Posted: Sun Jan 29, 2023 7:39 am
by akira463
How to fix my code? comments turns to be equal to each other? what could be the problem?

heres my code
{
/ppp secret
:foreach item in=[find] do={
	:local prof [get $item profile]
	:local comm [get $item comment]
	:local profCom "10 MBPS old 599 test"

	:if (($prof) = ($profCom)) do={
	:local accNum [:pick $comm ([:find $comm "Number: "] + 8) [:find $comm " Plan:"]]
	:local cost [:pick $comm ([:find $comm "Cost: "] + 6) ([:len $comm])]
	:local bill ($cost + 899)
	:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill"
	
	[/ppp secret set [find profile="10 MBPS old 599 test"] comment=$billmsg]
	:delay 1
	} else={
	:log warning "hays"
	}
	}
}


on this image acct number and bill are different .
p1.png




then when i run the code, they became same value
p2.png




Please help, thankyou

Re: How to fix my code? comments turns to be equal to each other?

Posted: Sun Jan 29, 2023 2:55 pm
by akira463
is there anyone ? please help .

Re: How to fix my code? comments turns to be equal to each other?

Posted: Sun Jan 29, 2023 3:58 pm
by tomislav91
is there anyone ? please help .
It seems that the issue is that the $billmsg variable is being overwritten in each iteration of the loop, resulting in all PPP secrets having the same comment. To fix this, you can modify the $billmsg variable by including the value of $item to create a unique value for each PPP secret:
:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill ($item)"
This way, the comment for each PPP secret will be unique and not equal to each other.

Re: How to fix my code? comments turns to be equal to each other?

Posted: Sun Jan 29, 2023 6:04 pm
by rextended
@tomislav91
It's time you try to understand what is being asked before answering...

@akira463
When you have two different comments like this
"Acc Number: 2021022 Plan: 35mbps Cost: 599"
"Acc Number: 2021021 Plan: 35mbps Cost: 4507"
You must search the original comment, for example "Acc Number: 2021022 Plan: 35mbps Cost: 599", for replace it with new comment with updated cost,
not generically the profile that have the user "10 MBPS old 599 test",
but you already have the item index $item inside the cycle, you not need to search again, just set the value on index,
and with putting the profile in the [find] you do not need to check it again inside if is present the comment or not.

I can not test the script because I do not have such profile and users, but must be like this:

revised code

/ppp secret
{
:local profCom "10 MBPS old 599 test"
 :foreach item in=[find where profile=$profCom] do={
	:local comm   [get $item comment]
	:local accNum [:pick $comm ([:find $comm "Number: "] + 8 ) [:find $comm " Plan:"]]
	:local cost   [:tonum [:pick $comm ([:find $comm "Cost: "] + 6) ([:len $comm])] ]
	:local bill   ($cost + 899)
	:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill"
	set $item comment=$billmsg
	:delay 1s
 }
}

Re: How to fix my code? comments turns to be equal to each other?

Posted: Mon Jan 30, 2023 12:54 am
by akira463
Thankyou again , sir rextended , youre such a life saver!!. thankyou so much , i hope that youll never get tired of helping me :-D :-D :-D . Godbless!

Re: How to fix my code? comments turns to be equal to each other?

Posted: Tue Aug 22, 2023 9:48 am
by copygigantic
It seems that the issue is that the $billmsg variable is being overwritten in each iteration of the loop, resulting in all PPP secrets having the same comment. To fix this, you can modify the $billmsg variable by including the value of $item to create a unique value for each PPP secretmini crossword:
:local billmsg "Acc Number: $accNum Plan: 10mbps Cost: $bill ($item)"
This way, the comment for each PPP secret will be unique and not equal to each other.
Find the original comment by searching for a phrase like "Acc Number: 2021022" Plan: 35mbps Cost: 599", to update the profile with a new note reflecting the new price, rather than the generic "10 MBPS old 599 test".