Huazhong University of Science and Technology
Visual Sound Instrument (Version 3.2)
VSI32 VBScript Design
VSI32 VBScript is a extension of VBScript of Microsoft. See VBScript document for how to prpgramming a script. Below is VSI32 related API.

1. FileDialog
Document.FileDialog(long type, LPCTSTR ext)

> Type=0: Read File Dialog, Type=1: Save File Dialog,
> ext=File filter

Sample:

> rc=Document.FileDialog(0,"*.txt")
> If rc = 0 Then
> name=Document.Buffer
> End If

2. Text File object
object.OpenTextFile(filename[, iomode[, create[, format]]])
Sample1:

> Dim fs, f
> Set fs=CreateObject("Scripting.FileSystemObject")
> Set f = fs.OpenTextFile("c:\temp\test.txt",2,True)
> f.WriteLine "Hi"
> f.Close

Sample2£º

Dim fs, f
Set fs=CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\temp\test.txt",1,False)
textin=f.readLine()
f.Close

3)Binary file
a) Open File
Document.openfile type, name

> type=0, Open file for read, Type=1, Open file for write
> name:File name and path

b) Close File
Document.closefile

c) Read Data
data=Document.readdata(type)

> type=0, Read a char; 1: Read a short ,2=Read a long, 3=Read a float , 4=Read a double

d)Write Data
Document.writedata type, data

> type=0, Write a char; 1: Write a short ,2=Write a long, 3=Write a float , 4=Write a double

4) API Communicate with VSI32
a) Read sample data length of VSI32
len=Document.ReadLen()

b)Read sample frequency of VSI32
Fs=Document.ReadFs()

c)Write sample data length of VSI32
Document.WriteLen(len)

d)Write sample frequency of VSI32
Document.WriteFs(Fs)

e)Read CH1 sample data of VSI32

f)Read CH2 sample data of VSI32

> Dim data(2048),data1(2048)
> For K = 0 To 2047 //Let data and data1 to double type , only double can be used
> data(k)=0.00001
> data1(k)=0.00001
> Next
> Rc=Document.ReadCH1(1024,data)
> Rc=Document.ReadCH2(1024,data1)

e)Write CH1 sample data of VSI32

f)Write CH2 sample data of VSI32

> For K = 0 To 2047
> data(k)=5.00*K
> data1(k)=-5.00*K
> Next
> Rc=Document.WriteCH1(1024,data)
> Rc=Document.WriteCH2(1024,data1)

g) Refresh VSI32
Document.DataChanged()

Sample:Generate a sine wave by script

> REM VB Script For VSI 32
> Dim data(2048),data1(2048)
> V=Document.InputBox("Amplitude:(1000-10000)")
> Document.WriteLen(2048)
> Document.WriteFs(5120)
> dt=1.0/5120
> For K = 0 To 2047
> data(k)=V*Cos(2.0*3.14*50*k*dt)
> data1(k)=V*Sin(2.0*3.14*50*k*dt)
> Next
> Rc=Document.WriteCH1(2048,data)
> Rc=Document.WriteCH2(2048,data1)
> Rc=Document.DataChanged()

[Return]
.