Author Topic: Storing BASE64 strings in user fields  (Read 1947 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Sr. Member
  • ****
  • Posts: 454
Storing BASE64 strings in user fields
« on: July 13, 2021, 02: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.
Visio 2021 Professional

Surrogate

  • Hero Member
  • *****
  • Posts: 1350
    • ShapeSheet™ Knowledge Base
Re: Storing BASE64 strings in user fields
« Reply #1 on: July 14, 2021, 04: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.
Code
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
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.
« Last Edit: July 14, 2021, 05:02:41 AM by Surrogate »

Surrogate

  • Hero Member
  • *****
  • Posts: 1350
    • ShapeSheet™ Knowledge Base
Re: Storing BASE64 strings in user fields
« Reply #2 on: July 14, 2021, 05:21:57 AM »
I continued my experiments for lulz:
I find this service for encode pictures to BASE64 strings
Just encode my picture

i can't put this BASE64 string to variable via VBA-editor. Just paste it as shape's text. i changed my code to
Code
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.
« Last Edit: July 14, 2021, 06:06:36 AM by Surrogate »

Visisthebest

  • Sr. Member
  • ****
  • Posts: 454
Re: Storing BASE64 strings in user fields
« Reply #3 on: July 14, 2021, 06: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.
Visio 2021 Professional