Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on July 13, 2021, 07:55:40 PM

Title: Storing BASE64 strings in user fields
Post by: Visisthebest on July 13, 2021, 07:55:40 PM
To save a bit of space in data I want to store in some user fields, I would like to use BASE64 strings instead of HEX strings.

Because the BASE64 strings can have some trailing = (equal) signs for padding, is there any potential issue with using them?

Because a string is always within quotes (chr(34)) I would think not, but maybe I'm overlooking something.

In BASE64, both a / and a + are also possible.
Title: Re: Storing BASE64 strings in user fields
Post by: Surrogate on July 14, 2021, 09:58:33 AM
I heard about the 65k character limit in User-defined cells (UDC) in oldest Visio versions. Just now i try this code for check how many characters i can put in UDC.
As first, I faced with limitation of string variable. For example variable with lenght of 1005000000 characters can work, but with 2000000000 can not.
Sub LimitUDC()
Dim sh As Shape, t As String
t = "=" & Space(1005000000) & "1"
Set sh = ActivePage.Shapes.ItemFromID(1)
sh.Cells("User.row_1").FormulaU = Chr(34) & t & Chr(34)
End Sub

This code can write these long strings to UDC, but it is very slow (https://visio.getbb.ru/images/ranks/visio_getbb_ru/huh.gif)
Just now i have not examples of BASE64 strings. Few years ago i meet in one old MS blog png-pictures stores as BASE64 strings.
Title: Re: Storing BASE64 strings in user fields
Post by: Surrogate on July 14, 2021, 10:21:57 AM
I continued my experiments for lulz:
I find this service for encode pictures to BASE64 strings (https://base64.guru/converter/encode/image). 
Just encode my picture (https://surrogate-tm.github.io/own/pics/rep.png)
(https://i.ibb.co/Kh58fHw/Converter-Base64.png)
i can't put this BASE64 string to variable via VBA-editor. Just paste it as shape's text. i changed my code to
Sub PNG-encodded()
Dim sh As Shape, t As String
Set sh = ActivePage.Shapes.ItemFromID(1)
t = sh.Text
sh.Cells("User.row_1").FormulaU = Chr(34) & t & Chr(34)
End Sub

In this case i get lenght of this string - 108008 characters.
Title: Re: Storing BASE64 strings in user fields
Post by: Visisthebest on July 14, 2021, 11:19:09 AM
Thank you for trying Surrogate I was unaware we can store a lot more than 64 Kilobytes in a shape's user field now very handy!

For me shorter BASE64 strings work fine but I haven't tried all kinds of Visio object methods to read the data, so hopefully won't run in to a surprise later.
Title: Re: Storing BASE64 strings in user fields
Post by: Surrogate on November 19, 2021, 09:50:48 AM
@Visisthebest,

For what purposes do you use Base64 ?
Title: Re: Storing BASE64 strings in user fields
Post by: Visisthebest on November 19, 2021, 10:46:11 AM
Storing binary data in Shape user fields.
Title: Re: Storing BASE64 strings in user fields
Post by: Surrogate on November 19, 2021, 11:19:00 AM
Quote from: Visisthebest on November 19, 2021, 10:46:11 AM
Storing binary data in Shape user fields.
Can you insert it as picture into shape ?
Title: Re: Storing BASE64 strings in user fields
Post by: Visisthebest on November 19, 2021, 12:44:52 PM
Never tried that maybe that works too!