KECCAK-256 Hash function in VB6 Or VBA - vb6

why keccak-256 is not the chilkat hash olgaritm ?
Dim crypt As New ChilkatCrypt2
crypt.EncodingMode = "hex_lower"
crypt.HashAlgorithm = **"keccak-256"???**
Dim bdSeed As New ChilkatBinData
success = bdSeed.AppendEncoded("43b337dec65a47b3362c9620a6e6ff39a1ddfa908abab1666c8a30a3f8a7ccccfc24a7914950b6405729a9313cec6ae5bb4a082f92d05ac49df4b6dd8387bfeb", "hex_lower")
MsgBox crypt.HashBdENC(bdSeed)
I wonder why this hash model does not exist in chilkat system?
Do you have any suggestion or function to VB6 for keccak hash?

Related

Assign Attachment Field To Variable in Access 2010

I'm trying to understand how to work with the new Attachment field that is available in Access 2010. I would like to assign the value from the table directly into a variable. I know that I can do this if I use an intermediary form, but this seems like sloppy coding to rely on a form in order to grab a value from a table. Is there some way to grab what is in an attachment field and assign it directly to a variable? I have multiple instances where this would be handy for me. The first instance is I want to grab a photo stored in an attachment field to assign to the ribbon. A second instance is to load a company logo from a table into a variable and keep it in memory to use throughout the program as needed.
The code I have so far is this, but it gives me a type mismatch error:
Dim ParentRS As Recordset, ChildRS As Recordset, Img As Attachment
Set ParentRS = CurrentDb.OpenRecordset("SELECT * FROM LtblImg;", dbOpenSnapshot)
If ParentRS.RecordCount > 0 Then
Set ChildRS = ParentRS("Img").Value
If ChildRS.RecordCount > 0 Then
Set Img = ChildRS("FileData")
End If
ChildRS.Close
End If
ParentRS.Close
Yes, Dim Img As Attachment looks tempting, but Attachment (which is actually Access.Attachment) refers to an Attachment control that could be used on a form (just like Access.TextBox) and does not appear to be suitable for your intended purpose.
The only native VBA type for storing this sort of binary data is an array of Byte values, but often when dealing with byte arrays we wind up looping through and processing them byte-by-byte, which is tedious and inefficient.
You might consider using a binary ADODB.Stream object as your "variable". You could create a function to retrieve the attachment bytes and return them in a Stream like so
Option Compare Database
Option Explicit
Public Function GetLogoAsStream() As ADODB.Stream
Dim cdb As DAO.Database, rstMain As DAO.Recordset, rstAttach As DAO.Recordset2, fldAttach As DAO.Field2
' Project references required for early binding:
' Windows Script Host Object Model
' Microsoft ActiveX Data Objects 2.8 Library
Dim fso As FileSystemObject, tempFileSpec As String
Static strm As ADODB.Stream
If strm Is Nothing Then
Set fso = New FileSystemObject
tempFileSpec = fso.GetSpecialFolder(TemporaryFolder) & "\" & fso.GetTempName
Set fso = Nothing
Set cdb = CurrentDb
Set rstMain = cdb.OpenRecordset( _
"SELECT [AttachmentFiles] " & _
"FROM [AttachmentsTable] " & _
"WHERE [Description]='SO logo'", _
dbOpenSnapshot)
Set rstAttach = rstMain("AttachmentFiles").Value
' make sure we use the correct file extension
tempFileSpec = tempFileSpec & "." & rstAttach.Fields("FileType").Value
Set fldAttach = rstAttach.Fields("FileData")
fldAttach.SaveToFile tempFileSpec
Set fldAttach = Nothing
rstAttach.Close
Set rstAttach = Nothing
rstMain.Close
Set rstMain = Nothing
Set cdb = Nothing
Set strm = New ADODB.Stream
strm.Type = adTypeBinary
strm.Open
strm.LoadFromFile tempFileSpec
Kill tempFileSpec
End If
strm.Position = 0
Set GetLogoAsStream = strm
End Function
and then if you had, say, a Report like this with an empty Image control
and an On Load event procedure like this to load the Image control's .PictureData from your "variable" (actually a Function returning an ADODB.Stream)
Private Sub Report_Load()
Me.LogoImage.PictureData = GetLogoAsStream.Read
End Sub
it could produce something like this

internet explorer XMLhttp instead of internet controlls?

I am using vba code to get information out of the web.
Everything is going fine, but it takes soooo long :(
I remember darkly that there is another way to get the information instead of creating an IE Object.
I think I dont need the IE Controlls. I am just loading one link after each other out of an sheet.
How is the other "way" working? Its something like XMLHttp?
Is there a difference for the code? shoudnt be, or?
thanks!
This is what I use:
Function getPage(URLStr As String) As MSHTML.HTMLDocument
Dim oHttpRequest As MSXML2.XMLHTTP60
Set oHttpRequest = New MSXML2.XMLHTTP60
With oHttpRequest
.Open "GET", URLStr, False
.send
End With
Dim oHTMLDoc As MSHTML.HTMLDocument
Set oHTMLDoc = New MSHTML.HTMLDocument
oHTMLDoc.body.innerHTML = oHttpRequest.responseText
Set getPage = oHTMLDoc
End Function
To call the function, use something like this:
Dim oHTMLDoc as MSHTML.HTMLDocument
Set oHTMLDoc = getPage("http://www.example.com")
For this, you'll need to add references to both "Microsoft XML, v6.0" and "Microsoft HTML Object Library", then you can use the MSHTML library to parse through the code as you need.

Export data from listview to OpenOffice VB6

I have a program that displays data from a CSV file into a ListView.
I then have a button called "Reports" - when I click this I want the data to be displayed from the ListView/CSV file in OpenOffice Calc.
This is my code:
Private Sub cmdReports_Click()
Dim oSM As Object
Dim oDesk As Object
Dim oDoc As Object
Dim oSheet As Object
Dim i As Integer
'Instanciate OOo : this line is mandatory with VB for OOo API
Set oSM = CreateObject("com.sun.star.ServiceManage…
'Create the first and most important service
Set oDesk = oSM.CreateInstance("com.sun.star.frame.D…
'Create a new doc
Set oDoc = oDesk.loadComponentFromURL("private:fact… "_blank", _
0, arg())
'Get the first sheet in the doc
Set oSheet = oDoc.getSheets().getByIndex(0)
With oSheet
For i = 1 To ListView1.ListItems.Count
.cells(i, 1) = ListView1.ListItems(i).Text
.cells(i, 2) = ListView1.ListItems(i).SubItems(1)
.cells(i, 3) = ListView1.ListItems(i).SubItems(2)
.cells(i, 4) = ListView1.ListItems(i).SubItems(3)
Next
End With
End Sub
At the moment all my button is doing giving me Run-time error '438' Object does not support this property or method
When I debug this line is highlighted:
.cells(i, 1) = ListView1.ListItems(i).Text
This code was written for Excel but I edited it so it can be displayed in OpenOffice Calc.
Can anyone help please?
Thanks
It means exactly what it says - the statement is using a property of method that isn't supported by the Ole Automation interface. First question: can you use a type library (see the References dialogue - is there something like OpenOffice Calc in the list)? Knowing what methods and properties are available at compile time is much better - you can do the same with Microsoft Excel. Then you could declare your variables as a specific type, rather than "As Object".
Not knowing OpenOffice, I looked for documentation on OpenOffice, and found the next best thing, Star Office. Try: http://www.openoffice.org/api/basic/man/tutorial/tutorial.pdf . Look at page 64, section 4.4 for documentation on the spreadsheets. The object model looks different to Office, which would explain your problem.
It looks as if you need to use the Sheet.getCellByPosition() method, rather than the Cells() method, e.g.
GetCell = oSheet.getCellByPosition (nColumn , nRow)

List audio input devices - VBA

I have a bit of a complex Access Database that I need to do some audio recording with. I have nearly everything working using outside solutions but I am forced to select my input device from within Access.
All that I need is some way to get a collection of devices or something from Windows and I can take it from there. http://www.vbmonster.com/Uwe/Forum.aspx/vb/32848/listing-all-audio-devices does something close to what I am looking for except that is the output instead of the input. I know that there will be no extremely easy way to accomplish this but I know it is possible, I just can't seem to find how.
The code you linked creates a SWbemObjectSet, then lists properties of its members (sound devices). From what I can tell, you want that object but don't want to list the properties ("output").
If that is correct, create a function which strips away the output statements and just returns the SWbemObjectSet object.
Public Function getSoundDevices(Optional strComputer As String = ".") As Object
Const cstrQuery As String = "Select * from Win32_SoundDevice"
Dim objWMIService As Object 'TypeName = SWbemServicesEx '
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set getSoundDevices = objWMIService.ExecQuery(cstrQuery, , 48)
Set objWMIService = Nothing
End Function
Then call the function to use the SWbemObjectSet as input for your other code.
Public Sub test_getSoundDevices()
Dim objSoundDevices As Object 'TypeName = SWbemObjectSet '
Dim objDevice As Object 'TypeName = SWbemObjectEx '
Set objSoundDevices = getSoundDevices()
For Each objDevice In objSoundDevices
'* do what you want for each sound device here *'
Debug.Print "ProductName: " & objDevice.ProductName
Next objDevice
Set objDevice = Nothing
Set objSoundDevices = Nothing
End Sub
Hmm, not the easiest question :-) I think you indeed need to invoke a native function.
Maby something like this:
http://msdn.microsoft.com/en-us/library/ms645598(v=vs.85).aspx
VB implementation in the bottom.
Good luck!

How to generate a GUID in VBScript?

I want to generate GUID strings in VBScript. I know that there's no built-in function in VBScript for generating one. I don't want to use random-generated GUIDs. Maybe there is an ActiveX object that can be created using CreateObject() that is sure to be installed on (newer) Windows versions that can generate a GUID?
Function CreateGUID
Dim TypeLib
Set TypeLib = CreateObject("Scriptlet.TypeLib")
CreateGUID = Mid(TypeLib.Guid, 2, 36)
End Function
This function will return a plain GUID, e.g., 47BC69BD-06A5-4617-B730-B644DBCD40A9.
If you want a GUID in a registry format, e.g., {47BC69BD-06A5-4617-B730-B644DBCD40A9}, change the function's last line to
CreateGUID = Left(TypeLib.Guid, 38)
How Can I Create a GUID Using a Script? (in: Hey, Scripting Guy! Blog) says this:
Set TypeLib = CreateObject("Scriptlet.TypeLib")
Wscript.Echo TypeLib.Guid
However, note that Scriptlet.TypeLib.Guid returns a null-terminated string, which can cause some things to ignore everything after the GUID. To fix that, you might need to use:
Set TypeLib = CreateObject("Scriptlet.TypeLib")
myGuid = TypeLib.Guid
myGuid = Left(myGuid, Len(myGuid)-2)
Wscript.Echo myGuid
' Returns a unique Guid on every call. Removes any cruft.
Function CreateGuid()
CreateGuid = Left(CreateObject("Scriptlet.TypeLib").Guid,38)
End Function
Set tlib = Server.CreateObject("Scriptlet.TypeLib")
strGuid = tlib.Guid

Resources