Problem with Javascript function

@zahaiak Look at this:


You have to decide whether a variable is of type string or number or else;

the following makes it clear: it works:
blocks (43)


blocks (46)

doesn't work if "x" is of type "string"

x of type number works:
blocks (47)

numbers as string work (there must be an internal conversion to data type "number", I guess)

4 Likes

Thanks guys
I think I have to fix the JavaScript function first
I'm not sure if it work or not.

Thanks again

1 Like

@zahaiak I don't think so. The JavaScript function looks good (change //Example to /star Example star/). It's more a problem of passing the variables right way coming from inside AppInventor.

2 Likes

Perhaps this script may be a little easier to use?

	function getbase64(name, taxNumber, date, total, vat) {
	var el = [name, taxNumber, date, total, vat];
	var base64 = []; 
	for (var i=0;i<el.length;i++) {
		base64.push(btoa(el[i]));
	}
    return base64.toString();
    }
2 Likes

Script of @TIMAI2 in https://jsfiddle.net/

- btoa

- atob

[Edited]

2 Likes

in blocks, seems to work

Double quotes are needed around strings, use number blocks for ...numbers.

window.AppInventor.setWebViewString(getbase64("TimAi2",1234567,"21-12-2021",147.24,14.7));
1 Like

Thanks for your help but it doesn't work with me. Could you please give me your aia file.

1 Like

Here you are
jsTest.aia (2.4 KB)

1 Like

Thanks,
But what I need is deferent. please look to the pictures.

HexToBase64

1 Like

OK sorry, but hopefully my code will help you to get the syntax for your script working :slight_smile:

1 Like

@zahaiak this works

testentesten.aia (4.1 KB)

in this example the label above shows the result: in this case "RESULT". Here you have only to adapt it to your app. I have written your function to a textBox that you can also use to test some JS code.

For example, change the return value to taxNumber (can be done in the textBox at runtime) - then you see the result in the label. You'll get taxNumber instead of "RESULT", one proof more that it works.

With the idea of @TIMAI2 and this code, we can get closer to what you are looking for.

Borrar_Base64_C.aia (3.7 KB)

Another version.

Borrar_Base64_D.aia (4.7 KB)

I'm so glad that you help me with this problem. You are done it so perfectly. However, Tags and Value Length should be hex number before covering them to Base 64. Please see the Hex Representation attached.Hex Representation

In your example hexadecimal sometimes use lowercase letters: f, d, a, .. and other uppercase: F
that changes the result of the base64

You are right they should be lowercase letters. How to make them hexadecimal lowercase letters.

Block
Text
upcase/downcase

I'm sorry, I confused you. The way the project work is
First is (from Text to bytes)
Second is (from bytes to Hex)
Then (from Hex To base64)
this way will work perfectly.

Thanks again for your help and your your patience

for all a , b , cX , if a R b and b R c , then a R c .

1 Like

Thanks for everything you done for me. I'm really grateful it.