vbscript


convert a zip file to base64 using vbs in UFT


I have a requirement of converting a zip file from my local machine to base64.
Get/Read the path name from the excel sheet row
convert the file in the path (zip file) to base 64 string
Copy the base 64 value to next column in the excel sheet.
Tried a few but did not work.
Current Code:
Dim inByteArray, base64Encoded
inByteArray = readBytes("F:path/file.zip")
base64Encoded = encodeBase64(inByteArray)
Private Function readBytes(file)
Dim inStream
' ADODB stream object used
Set inStream = CreateObject("ADODB.Stream")
' open with no arguments makes the stream an empty container
inStream.Open
inStream.Type = TypeBinary
inStream.LoadFromFile(file)
readBytes = inStream.Read()
End Function
Private Function encodeBase64(bytes)
Dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
' Create temporary node with Base64 data type
Set EL = DM.CreateElement("tmp")
EL.DataType = "bin.base64"
' Set bytes, get encoded String
EL.NodeTypedValue = bytes
encodeBase64 = EL.Text
End Function
Error 1 in the line inStream.type = TypeBinary:
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
Error 2 in the line readBytes = inStream.Read():
Operation is not allowed in this context.
Error 3 in the line EL.NodeTypedValue = bytes:
Type mismatch
Looks like you got the code from here, but didn't include
Const TypeBinary = 1
Adding this will avoid the "Arguments are of the wrong type ..." error.
Perhaps careful copy will solve your other problems too.
Thanks for that :)
Further for excel sheet read and write I used the below code which helped in achieving my target. Thank you
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("F:\path")
Set ws = objWorkbook.Sheets("Sheet1")
Set ws2 = objWorkbook.Sheets("Sheet2")
rowcount = ws.usedrange.rows.count
for j = 1 to rowcount
fieldvalue = ws.cells(j,1)
inByteArray = readBytes(fieldvalue)
base64Encoded = encodeBase64(inByteArray)
ws2.cells(j,1) = base64Encoded
next

Related Links

how to replace #VARIABLE in text file with value of Emails in xml file
Make a permanent mapping - vb script
Identifying and removing characters from string in VBS using regexp
QTP/VBScript - Function return value is not passed during the 3rd iteration
extract JavaTree Item Color using QTP
Get date format (American or Australian) on a domain controller for Active Directory Script
Print function type mismatch in VBScript
Getting server's CPU usage percentage VBScript
VBS Calculator issues
VBScript To Remove Number from filename
Sparx Enterprise Architect to get the Tagged ┬┤Value from otDiagram VB Script code
Can we code a hold key function in a vb script
Microsoft.Jet.OLEDB.4.0 - Provider cannot be found. It may not be properly installed
Restarting Computer via VBS
Can we number tag items on a window like in speech recognition
saving file with download prompt with vbscript

Categories

HOME
client
hive
fluentd
path-finding
smarty
fft
yarn
microservices
blueprintjs
convolution
vifm
spring-xd
wheelnav.js
collectd
usergrid
event-handling
lombok
django-simple-history
uitypeeditor
database-replication
normalizr
text-rendering
functional-testing
kvc
core-text
restful-authentication
virtualdub
fopen
spring-mybatis
publish
dbclient
facebook-apps
primitive
nat
pim
webtest
y86
mapdb
nssegmentedcontrol
appfabric
restlet
space-complexity
hue
texmaker
spring-security-kerberos
nxlog
s
filepicker
prolog-setof
dandelion
dotnetzip
recursive-datastructures
magma
gcsfuse
hittest
lync-client-sdk
or-tools
mediaelement
specrun
objective-c-swift-bridge
log4c
savon
skobbler-maps
hexdump
pagerank
itextpdf
historian
pervasive-sql
maven-tomcat-plugin
wso2cloud
comobject
wordml
wireshark-dissector
content-length
rgeo
interrupted-exception
vstest.console.exe
pick
angularjs-ng-click
asp.net-dynamic-data
sgen
starcluster
system.net.webexception
dir
tidy
jmapviewer
file-locking
dataadapter
hungarian-algorithm
sqlperformance
anonymous-methods
gcj
tomcat-valve
w3wp.exe
gin
modelstate
sef
memory-size
photoshop-cs4
premature-optimization
data-acquisition
signal-handling

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App