M
MikeHammadi
Guest
I found a free source code for storing live prices. It saves information about the stock prices like open-high-low... also it saves the stocks description which is a string. Everything is working fine except adding stock description in Arabic language.
When I add a new stock with description written in arabic , stock not added
I am using vb.net . and saving data to master file .
I tried to follow the code of adding a new stock (security) but i didnt find the solution. I am new vb developer.
Here is the code:
Here is the main form where we add the new security:
MainForm.vb
PfG.Portfolio(PortfolioIndex).NewSecurity(seclist(i).symbol,Strings.Left(seclist(i).issueName, 16),calStartDate1.Text)
Portofolio.vb
Friend Stocks As New ArrayList
Public Function NewSecurity(ByVal Symbol As String, ByVal Desc As String, ByVal StartDate As Date) As Metafile
If Me.SecCount = 0 Then If this is a new metastock folder
Dim data(52) As Byte
data.Initialize()
WriteTo(data, dir, "MASTER", 1, False)
ReDim data(191)
WriteTo(data, dir, "EMASTER", 1, False)
ElseIf Me.SecCount = 255 AndAlso Not (IO.File.Exists(dir & "XMASTER")) Then
If Me.Exists(Symbol) Then Throw New Exception("Symbol already in database")
Dim data(149) As Byte
WriteTo(data, dir, "XMASTER", 1, False)
Else If the folder exists.. check if security already exists
If Me.Exists(Symbol) Then Throw New Exception("Symbol already in database")
End If
Create, add and retun new security
Dim x As New Metafile(dir, Symbol, Desc, StartDate, Me.SecCount)
x.Save(True)
Stocks.Add(x)
SecCount += 1
Return x
End Function
MetaFile.vb
CREATES A NEW METASTOCK SECURITY FILE BASED ON PATH+FILENAME, SYMBOL,NAME, STARTDATE AND LAST RECORD NUMBER
Friend Sub New(ByVal path As String, ByVal Symbol As String, ByVal Desc As String, ByVal StartDate As Date, ByVal LastRecNum As Integer)
If path.Chars(path.Length - 1) <> "\" Then path &= "\"
If LastRecNum < 255 Then TO BE STORED IN MASTER
Dim temp() As Byte
Dim mfr As New MasterFileRecord
Dim emfr As New EMasterFileRecord
ReDim temp(0)
temp(0) = Convert.ToByte(GetFreeFilenum(IO.Path.GetDirectoryName(path)))
mfr.symbol = Symbol
emfr.symbol = Symbol
mfr.issueName = Desc
emfr.issueName = mfr.issueName
mfr.fileType = 25856
emfr.fileType = 25856
mfr.recordLength = 28
mfr.v28 = False
emfr.v28 = False
emfr.id_code = 66
emfr.EMFields = New Fields(&H7F) This is for Daily w/ OI and OP, needs to be changed for Intraday
WriteTo(MasterByteArray(mfr), IO.Path.GetDirectoryName(path), "MASTER", 0, True)
WriteTo(EMasterByteArray(emfr), IO.Path.GetDirectoryName(path), "EMASTER", 0, True)
WriteTo(temp, IO.Path.GetDirectoryName(path), "MASTER", 1, False)
WriteTo(temp, IO.Path.GetDirectoryName(path), "MASTER", 3, False)
WriteTo(temp, IO.Path.GetDirectoryName(path), "EMASTER", 1, False)
WriteTo(temp, IO.Path.GetDirectoryName(path), "EMASTER", 3, False)
CreateFile(path, mfr.getFileName())
ReDim temp(27)
WriteTo(temp, IO.Path.GetDirectoryName(path), mfr.getFileName(), 0, True)
save data to class
Me.File = IO.Path.GetDirectoryName(path) & "\" & mfr.getFileName()
Me.RecLen = mfr.recordLength
Me.RecCount = mfr.recordCount
Me.Name = mfr.issueName
Me.Symbol = mfr.symbol
Me.FDate = System.DateTime.Parse(mfr.firstDate)
Me.LDate = System.DateTime.Parse(mfr.lastDate)
Me.FileNum = mfr.fileNum
Me.TimeFrame = mfr.timeFrame
Me.AutoRun = mfr.autorun
Me.FileType = mfr.fileType
Me.FirstDateLng = emfr.firstdatelng
Me.v28 = mfr.v28
Me.IsX = False
Me.StoredFields = emfr.EMFields
Else
Dim xmfr As New XMasterFileRecord
Dim xm As New XMasterFileDescriptor
Dim temp() As Byte = ReadFile(path & "XMASTER")
Dim temp2(1) As Byte
Dim temp3(1) As Byte
Dim FileNum As Long = Convert.ToInt16(temp(xm.NEXT_FILE_0) + temp(xm.NEXT_FILE_1) * 2 ^ 8)
Dim NumberofFiles As Long = Convert.ToInt16(temp(xm.NUM_FILES_0) + temp(xm.NUM_FILES_1) * 2 ^ 8)
xmfr.firstDate = StartDate.Date
xmfr.lastDate = StartDate.Date
xmfr.issueName = Desc
xmfr.symbol = Symbol
xmfr.timeFrame = "D"
xmfr.fileNum = FileNum
xmfr.XMFields = New Fields(&H7F) This is for Daily w/ OI and OP, needs to be changed for Intraday
FileNum = FileNum + 1
NumberofFiles = NumberofFiles + 1
temp2(0) = Convert.ToByte(FileNum And &HFF)
temp2(1) = Convert.ToByte((FileNum And &HFF00) >> 8)
temp3(0) = Convert.ToByte(NumberofFiles And &HFF)
temp3(1) = Convert.ToByte((NumberofFiles And &HFF00) >> 8)
WriteTo(XMasterByteArray(xmfr), path, "XMASTER", 0, True)
WriteTo(temp3, path, "XMASTER", xm.NUM_FILES_0 + 1, False)
WriteTo(temp3, path, "XMASTER", xm.NNUM_FILES_0 + 1, False)
WriteTo(temp2, path, "XMASTER", xm.NEXT_FILE_0 + 1, False)
CreateFile(path, xmfr.getFileName())
ReDim temp(27)
WriteTo(temp, path, xmfr.getFileName(), 0, True)
save data to class
Me.File = IO.Path.GetDirectoryName(path) & "\" & xmfr.getFileName()
Me.RecLen = 28
Me.RecCount = 7
Me.Name = xmfr.issueName
Me.Symbol = xmfr.symbol
Me.FDate = System.DateTime.Parse(xmfr.firstDate)
Me.LDate = System.DateTime.Parse(xmfr.lastDate)
Me.FileNum = xmfr.fileNum
Me.TimeFrame = xmfr.timeFrame
Me.AutoRun = False
Me.FileType = 25856
Me.v28 = False
Me.IsX = True
Me.StoredFields = xmfr.XMFields
End If
End Sub
MasterFileRecord.vb
Public Function Initialize(ByRef data() As Byte, ByRef recNum As Short) As Object
Dim recordBase As Short
Dim m As New MasterFileDescriptor
recordBase = (recNum + 1) * m.MASTER_RECORD_LENGTH
fileNum = data(recordBase + m.FILE_NUM)
fileType = CStr(readShort(data, recordBase + m.FILE_TYPE_0))
recordLength = data(recordBase + m.RECORD_LENGTH)
recordCount = data(recordBase + m.RECORD_COUNT)
issueName = readString(data, recordBase + m.ISSUE_NAME_0, m.ISSUE_NAME_LEN)
If (data(recordBase + m.CT_V2_8_FLAG) = 89) Then
v28 = True
Else
v28 = False
End If
firstDate = readDate(data, recordBase + m.FIRST_DATE_0)
lastDate = readDate(data, recordBase + m.LAST_DATE_0)
timeFrame = Chr(data(recordBase + m.TIME_FRAME))
idaTime = data(recordBase + m.IDA_TIME_0)
symbol = readString(data, recordBase + m.SYMBOL_0, m.SYMBOL_LEN)
If (data(recordBase + m.CT_V2_8_FLAG) = 42) Then
autorun = True
Else
autorun = False
End If
End Function
Friend Function readString(ByRef buffer() As Byte, ByRef offset As Integer, ByRef length As Integer) As String
Dim tempstring As String
While length + 1 > 0
If buffer(offset + length) <> 0 Then
tempstring = Chr(buffer(offset + length)) + tempstring
End If
length = length - 1
End While
readString = Trim(tempstring)
End Function
Thats all the code related to adding new security. so please can you help me find the code that prevent adding when the security description is written in arabic language.
Thanks
Continue reading...
When I add a new stock with description written in arabic , stock not added
I am using vb.net . and saving data to master file .
I tried to follow the code of adding a new stock (security) but i didnt find the solution. I am new vb developer.
Here is the code:
Here is the main form where we add the new security:
MainForm.vb
PfG.Portfolio(PortfolioIndex).NewSecurity(seclist(i).symbol,Strings.Left(seclist(i).issueName, 16),calStartDate1.Text)
Portofolio.vb
Friend Stocks As New ArrayList
Public Function NewSecurity(ByVal Symbol As String, ByVal Desc As String, ByVal StartDate As Date) As Metafile
If Me.SecCount = 0 Then If this is a new metastock folder
Dim data(52) As Byte
data.Initialize()
WriteTo(data, dir, "MASTER", 1, False)
ReDim data(191)
WriteTo(data, dir, "EMASTER", 1, False)
ElseIf Me.SecCount = 255 AndAlso Not (IO.File.Exists(dir & "XMASTER")) Then
If Me.Exists(Symbol) Then Throw New Exception("Symbol already in database")
Dim data(149) As Byte
WriteTo(data, dir, "XMASTER", 1, False)
Else If the folder exists.. check if security already exists
If Me.Exists(Symbol) Then Throw New Exception("Symbol already in database")
End If
Create, add and retun new security
Dim x As New Metafile(dir, Symbol, Desc, StartDate, Me.SecCount)
x.Save(True)
Stocks.Add(x)
SecCount += 1
Return x
End Function
MetaFile.vb
CREATES A NEW METASTOCK SECURITY FILE BASED ON PATH+FILENAME, SYMBOL,NAME, STARTDATE AND LAST RECORD NUMBER
Friend Sub New(ByVal path As String, ByVal Symbol As String, ByVal Desc As String, ByVal StartDate As Date, ByVal LastRecNum As Integer)
If path.Chars(path.Length - 1) <> "\" Then path &= "\"
If LastRecNum < 255 Then TO BE STORED IN MASTER
Dim temp() As Byte
Dim mfr As New MasterFileRecord
Dim emfr As New EMasterFileRecord
ReDim temp(0)
temp(0) = Convert.ToByte(GetFreeFilenum(IO.Path.GetDirectoryName(path)))
mfr.symbol = Symbol
emfr.symbol = Symbol
mfr.issueName = Desc
emfr.issueName = mfr.issueName
mfr.fileType = 25856
emfr.fileType = 25856
mfr.recordLength = 28
mfr.v28 = False
emfr.v28 = False
emfr.id_code = 66
emfr.EMFields = New Fields(&H7F) This is for Daily w/ OI and OP, needs to be changed for Intraday
WriteTo(MasterByteArray(mfr), IO.Path.GetDirectoryName(path), "MASTER", 0, True)
WriteTo(EMasterByteArray(emfr), IO.Path.GetDirectoryName(path), "EMASTER", 0, True)
WriteTo(temp, IO.Path.GetDirectoryName(path), "MASTER", 1, False)
WriteTo(temp, IO.Path.GetDirectoryName(path), "MASTER", 3, False)
WriteTo(temp, IO.Path.GetDirectoryName(path), "EMASTER", 1, False)
WriteTo(temp, IO.Path.GetDirectoryName(path), "EMASTER", 3, False)
CreateFile(path, mfr.getFileName())
ReDim temp(27)
WriteTo(temp, IO.Path.GetDirectoryName(path), mfr.getFileName(), 0, True)
save data to class
Me.File = IO.Path.GetDirectoryName(path) & "\" & mfr.getFileName()
Me.RecLen = mfr.recordLength
Me.RecCount = mfr.recordCount
Me.Name = mfr.issueName
Me.Symbol = mfr.symbol
Me.FDate = System.DateTime.Parse(mfr.firstDate)
Me.LDate = System.DateTime.Parse(mfr.lastDate)
Me.FileNum = mfr.fileNum
Me.TimeFrame = mfr.timeFrame
Me.AutoRun = mfr.autorun
Me.FileType = mfr.fileType
Me.FirstDateLng = emfr.firstdatelng
Me.v28 = mfr.v28
Me.IsX = False
Me.StoredFields = emfr.EMFields
Else
Dim xmfr As New XMasterFileRecord
Dim xm As New XMasterFileDescriptor
Dim temp() As Byte = ReadFile(path & "XMASTER")
Dim temp2(1) As Byte
Dim temp3(1) As Byte
Dim FileNum As Long = Convert.ToInt16(temp(xm.NEXT_FILE_0) + temp(xm.NEXT_FILE_1) * 2 ^ 8)
Dim NumberofFiles As Long = Convert.ToInt16(temp(xm.NUM_FILES_0) + temp(xm.NUM_FILES_1) * 2 ^ 8)
xmfr.firstDate = StartDate.Date
xmfr.lastDate = StartDate.Date
xmfr.issueName = Desc
xmfr.symbol = Symbol
xmfr.timeFrame = "D"
xmfr.fileNum = FileNum
xmfr.XMFields = New Fields(&H7F) This is for Daily w/ OI and OP, needs to be changed for Intraday
FileNum = FileNum + 1
NumberofFiles = NumberofFiles + 1
temp2(0) = Convert.ToByte(FileNum And &HFF)
temp2(1) = Convert.ToByte((FileNum And &HFF00) >> 8)
temp3(0) = Convert.ToByte(NumberofFiles And &HFF)
temp3(1) = Convert.ToByte((NumberofFiles And &HFF00) >> 8)
WriteTo(XMasterByteArray(xmfr), path, "XMASTER", 0, True)
WriteTo(temp3, path, "XMASTER", xm.NUM_FILES_0 + 1, False)
WriteTo(temp3, path, "XMASTER", xm.NNUM_FILES_0 + 1, False)
WriteTo(temp2, path, "XMASTER", xm.NEXT_FILE_0 + 1, False)
CreateFile(path, xmfr.getFileName())
ReDim temp(27)
WriteTo(temp, path, xmfr.getFileName(), 0, True)
save data to class
Me.File = IO.Path.GetDirectoryName(path) & "\" & xmfr.getFileName()
Me.RecLen = 28
Me.RecCount = 7
Me.Name = xmfr.issueName
Me.Symbol = xmfr.symbol
Me.FDate = System.DateTime.Parse(xmfr.firstDate)
Me.LDate = System.DateTime.Parse(xmfr.lastDate)
Me.FileNum = xmfr.fileNum
Me.TimeFrame = xmfr.timeFrame
Me.AutoRun = False
Me.FileType = 25856
Me.v28 = False
Me.IsX = True
Me.StoredFields = xmfr.XMFields
End If
End Sub
MasterFileRecord.vb
Public Function Initialize(ByRef data() As Byte, ByRef recNum As Short) As Object
Dim recordBase As Short
Dim m As New MasterFileDescriptor
recordBase = (recNum + 1) * m.MASTER_RECORD_LENGTH
fileNum = data(recordBase + m.FILE_NUM)
fileType = CStr(readShort(data, recordBase + m.FILE_TYPE_0))
recordLength = data(recordBase + m.RECORD_LENGTH)
recordCount = data(recordBase + m.RECORD_COUNT)
issueName = readString(data, recordBase + m.ISSUE_NAME_0, m.ISSUE_NAME_LEN)
If (data(recordBase + m.CT_V2_8_FLAG) = 89) Then
v28 = True
Else
v28 = False
End If
firstDate = readDate(data, recordBase + m.FIRST_DATE_0)
lastDate = readDate(data, recordBase + m.LAST_DATE_0)
timeFrame = Chr(data(recordBase + m.TIME_FRAME))
idaTime = data(recordBase + m.IDA_TIME_0)
symbol = readString(data, recordBase + m.SYMBOL_0, m.SYMBOL_LEN)
If (data(recordBase + m.CT_V2_8_FLAG) = 42) Then
autorun = True
Else
autorun = False
End If
End Function
Friend Function readString(ByRef buffer() As Byte, ByRef offset As Integer, ByRef length As Integer) As String
Dim tempstring As String
While length + 1 > 0
If buffer(offset + length) <> 0 Then
tempstring = Chr(buffer(offset + length)) + tempstring
End If
length = length - 1
End While
readString = Trim(tempstring)
End Function
Thats all the code related to adding new security. so please can you help me find the code that prevent adding when the security description is written in arabic language.
Thanks
Continue reading...