Code Snippet programs

Does anyone still use code snippet like programs?

I am thinking of writing one in Xojo, to handle xojo clipboard formats directly, and extract info like the name etc, and just use a sqlite database to store the data.

I whipped up this code, seems to capture anything from xojo, I am running latest version (2023r4) if anyone wants to test it with earlier versions etc

Code to read the clipboard

// Create a new instance of the Clipboard class
Var c As New Clipboard

// Check if the clipboard contains data of type "CbCl"
If c.RawDataAvailable("CbCl") Then
  label2.Text = "CbCl"
  
  // Retrieve raw data from the clipboard
  Var rawData As String = c.RawData("CbCl")
  
  // Extract a specific part of the raw data to determine the object type
  Var objectType As String = rawData.MiddleBytes(20, 8)
  
  // Extract the object's name from the raw data
  Var name As String = rawData.MiddleBytes(28, 64)
  Var nameParts() As String = name.SplitBytes(DecodeHex("000000000000000000000000"))
  nameParts = nameParts(1).SplitBytes(DecodeHex("000000"))
  name = nameParts(1)
  name = name.RightBytes(name.Length - 1)
  name = name.NthField(DecodeHex("20"), 1)
  
  // Determine the type of object and update the UI accordingly
  Select Case objectType
  Case "BlokpObj"
    label1.Text = "Class, Module or Class Interface: " + name
  Case "BlokpDWn"
    label1.Text = "Window or Container: " + name
  Case "Blokcolr"
    label1.Text = "Color Group: " + name
  Case "BlokpACX"
    label1.Text = "OLE Component: " + name
  Case "BlokWrKr"
    label1.Text = "Worker: " + name
  Case "BlokpDTb"
    label1.Text = "Toolbar: " + name
  Case "BlokpRpt"
    label1.Text = "Report: " + name
  Case "BlokpFTy"
    label1.Text = "File Type Group: " + name
  Case "BlokpMnu"
    label1.Text = "Menu Bar: " + name
  Else
    label1.Text = "Unknown Obj: " + name
    System.DebugLog("Unknown Item: " + objectType)
  End Select
  
  // Display the raw data in hex format in TextArea1
  TextArea1.Text = EncodeHex(rawData)
  
  // Check if the clipboard contains data of type "RBCT"
ElseIf c.RawDataAvailable("RBCT") Then
  label2.Text = "RBCT"
  
  // Processing for "RBCT" data type
  Dim s As String = c.RawData("RBCT")
  Dim sl As String = s.Middle(8,50)
  Dim x() As String = sl.SplitBytes(DecodeHex("00"))
  Dim y() As String = x(1).SplitBytes(DecodeHex("01"))
  
  label1.Text = x(0) + ":" + y(1)
  TextArea1.Text = EncodeHex(s)
  
  // Check if the clipboard contains data of type "RSCI"
ElseIf c.RawDataAvailable("RSCI") Then
  label2.Text = "RSCI"
  label1.Text = "Sub or Function (), Event, method, Const or Property"
  
  // Retrieve text data from the clipboard and display it
  Var s As String = c.Text
  TextArea1.Text = s
  
  // Check if the clipboard contains plain text
ElseIf c.TextAvailable Then
  label2.Text = "Text"
  
  // Retrieve and display the text data
  Var s As String = c.Text
  TextArea1.Text = s
  
  // If none of the above conditions are met, log an unknown type
Else
  label2.Text = "Unknown"
  System.DebugLog("Unknown clipboard data type")
End If

Code to write back data to Clipboard to paste in Xojo

Dim c As New Clipboard
If label2.Text="Text" Or label2.Text="RSCI" Then
  Dim s As String = TextArea1.Text
  c.Text = s
ElseIf label2.Text="Unknown" Then
  Return
Else
  Dim s As String = DecodeHex(TextArea1.Text)
  c.RawData(Label2.Text)= s
End If

its difficult and time-consuming to put all together in a working code snippet.
usually i copy paste things from a other good up-to-date project.

1 Like

That’s my current go to, but trying to remember where the “current” module I am looking for is or what project it’s in :slight_smile:

maybe you need a database-based knowledge management tool too :slight_smile:

1 Like

I have a folder on my desktop that contains exported modules, classes etc. When I need something, I open the folder & drag the component into the Navigator of the project I’m working on.

I also make extensive use of template projects.

1 Like

I put as many super-useful code and extentions in modules