|
Don't read the entire file into a string variable. That isn't necessary at all an makes you job that much harder. What you do is open 2 files. 1 is the file you want to convert, 2 is the file you want to convert to. You do the same thing you did in your sample code with the LineInput but you look for the '*' character and split the string into two strings. Then recombine the strings into the new format and write that into the second file.
Private Sub Convert()
Dim SourceString As String
Dim TargetString As String
Dim Parsed() As String
FileOpen(1, "C:\Source.txt", OpenMode.Input)
FileOpen(2, "C:\Target.txt", OpenMode.Output)
Do Until EOF(1)
SourceString = LineInput(1)
Parsed = SourceString.Split("*")
TargetString = Parsed(1) & "|" & Parsed(0)
PrintLine(2, TargetString)
Loop
FileClose(1, 2)
End Sub
RageInTheMachine9532
|
|
|
|
|
That code works.....for the most part. The problem is if the question/answer set is not all on one line it will crash with a "Index was outside the bounds of the array". error. one condition that will cause this is having a question/answer run over onto another line. Here's the current code:
Private Sub mnu_file_convert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_file_convert.Click
currsep = txt_current.Text
newsep = txt_desired.Text
OpenFileDialog.Filter = "Text Files (*.txt)|*.txt"
SaveFileDialog.Filter = "Text Files (*.txt)|*.txt"
OpenFileDialog.ShowDialog()
SaveFileDialog.ShowDialog()
If OpenFileDialog.FileName <> "" And SaveFileDialog.FileName <> "" Then
FileOpen(1, OpenFileDialog.FileName, OpenMode.Input)
FileOpen(2, SaveFileDialog.FileName, OpenMode.Output)
'Stop
Do Until EOF(1)
SourceString = LineInput(1)
Parsed = SourceString.Split(currsep)
If lst_current.SelectedIndex = 1 And lst_desired.SelectedIndex = 0 Then
TargetString = Parsed(1) & newsep & Parsed(0)
PrintLine(2, TargetString)
Else
TargetString = Parsed(0) & newsep & Parsed(1)
PrintLine(2, TargetString)
End If
Loop
End If
End Sub
End Class
|
|
|
|
|
OK. Then when you parse the string (TargetString=...). Check to see if the array that is returned has 2 elements in it. If not, then you have to go back and read the next line and append it to the one you already have, then parse it again and it should work. Thing is, this will only work if you have 1 question and 1 answer per line or two. If the second line contains the rest of a question, then and answer, then starts another question, you'll run into problems. I know '*' comes between a question and its answer, but is there a second seperator that appears between answer followed by a question?
RageInTheMachine9532
|
|
|
|
|
Hi,
I need speech to text examples.pls help me.
|
|
|
|
|
Could you be a little more specific? What library/controls/API package(s) are you using to do the speech recognition?
Microsoft has at least 3 packages that I know of, then there are third party packages...
RageInTheMachine9532
|
|
|
|
|
hi,
I am using Sapi.could u give some guidence.
|
|
|
|
|
Well, SAPI 5.2 is the foundation of the Speech Application SDK, but version one of this SDK is at Beta 3 right now. You can try it out by following the Getting Started for First-Time Users here[^]. There is also a pretty decent tutorial on it here[^].
I haven't used it myself, but I tried out the tutorial with no real problems.
RageInTheMachine9532
|
|
|
|
|
I have a program that needs to have focus all the time but have no idea where to start.
The program is set to form on top but I do not want it to lose focus. Please help!!
|
|
|
|
|
First, your Application never really has the focus. It's title bar changes color because one of it's child controls has the focus. A form is nothing but a control, but a control that can contain other controls.
Individual controls get and lose focus. Its a pain to manage if your trying to retain the input focus to just your app (form). You have to keep track of which control actually has the focus and if none of your child controls has the focus anymore, which control do you give it back to?
A better way would be to redo the form(s) your using and show them as system modal dialog boxes. This way, Windows manages the focus for you and you can't leave the app until the dialog box goes away. Search the documentation for ShowDialog to see what I mean.
Your app needs to have the focus all the time? Why? It kind of make using the rest of the system a pain to use if you can't so much as click on the "Start" button...
RageInTheMachine9532
|
|
|
|
|
I need to validate a password field with RegularExpression Validator. The validation logic is bit complex for me. Can anyone help me out with this
Password must be a minimum of 8 characters and contain a combination of 3 of the following characters:
- numbers
- upper case letters
- lower case letters
- special character (*%$)
I need this urgently. PLEASE SOMEONE PLS HELP.
THANKS in advance
|
|
|
|
|
A regular expression to do this (mostly because of the 3 out of 4 clause, would be incredibly long and would require intensive CPU time and quite a bit of memory. I would recommend that you instead create a custom validator that enumerates the characters and keeps a count, something like this:
' Assume password is in a string variable called "password"
If password.Length < 8 Then Return False
Dim i As Integer = 0
Dim b1 As Boolean
Dim b2 As Boolean
Dim b3 As Boolean
Dim b4 As Boolean
For Each c As Char In password
If Char.IsLetter(c) Then
If Char.IsLower(c) And Not b1 Then
b1 = True
i++
Else If Not b2
b2 = True
i++
End If
Else If Char.IsNumber(c) And Not b3 Then
b3 = True
i++
Else If (c = "*"c Or c = "%"c Or c = "$"c) And Not b4 Then
b4 = True
i++
End If
Next
If i >= 3 Then Return True
Else Return False
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Dear All,
I used OLe Container in VB6.0 to upload image to database.
The image is saved in database as compounded file binary.
Now I am using VB.NET to retrieve the file.. but somehow I could not extract the
embedded file from that OLE Binary.
Does someone have a workaround for this?
Much Appreciated.
Sandy
|
|
|
|
|
This should work for you. I know that it works with MS-Access. Assuming you table contains the following fields
IMAGE_ITEM_ID : Long
NAME : Text
IMAGE : OLE Object
Public Sub GetItem(ByVal itemId As Long)
Dim sqlQuery As String ' the query to execute
Dim image() As Byte ' the image to get
Dim name as String ' the name of the image
sqlQuery = "SELECT IMAGE_ITEM_ID, NAME, IMAGE " & _
"FROM IMAGE_ITEM " &_
"WHERE IMAGE_ITEM_ID = " & itemId
Try
' instanciate a connection object
Dim conn As OleDb.OleDbConnection = GetConnection()
' instanciate a command object
Dim com As New OleDbCommand(sqlQuery, conn)
' open the connection
com.Connection.Open()
' create a read to read the database
Dim reader As OleDbDataReader
' open the reader
reader = com.ExecuteReader(CommandBehavior.CloseConnection)
' read the first record
If (reader.Read()) Then
' get the name of the image
name = reader.GetString(1)
' get the image
itemData.Image = CType(reader.Item(2), Byte())
End If
' clean up after yourself
reader.Close()
com.Connection.Close()
conn.Dispose() 'release memory to garbage collection
com.Dispose() 'release memory to garbage collection
Catch eOleDb As OleDb.OleDbException
MsgBox("OleDb Error - GetItem - [" & eOleDb.Message & "]")
End Try
End Sub
I hope it works for you.
|
|
|
|
|
What is the best practice for generating a standard report in a VB.NET app?
I have tabbed form a user fills out then clicks file, print to print the record just created. Printing the data entry screen is not an option. For instance you fill out a customer order then you want to print the order. Do you create another windows form or is there a special type of form for printing?
I know this is a newbie question but I am just looking for some general guidance not a step by step walk through.
Thanks,
Sean
|
|
|
|
|
Hi Sean. You could use a dedicated report control, like Crystal Reports for this. You could also investigate the PrintDocument class - to print a customer order, you could either sub-class PrintDocument or add your own event handler to respond to the PrintDocument's PrintPage event. The .NET SDK documentation has some examples.
|
|
|
|
|
hello to all
i am using this code to send a message from my system (sys 1) to the other system (sys 2).
its working fine..... for this i need to use APIs. but i want to send a message using the shell command. can any body give the exact syntax for it ?.
next one ... is there any way to know in/from the sencond system (sys 2) ( ... to which i am sending the message ) that it has got the message when ever i send a message to sys 2 ?.
so that i can show a popup (just like msn messenger do) or play some sound when ever sys 2 gets a message from sys 1.
here is the code ...
Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (yServer As Any, yToName As Byte, yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
Private Const NERR_Success As Long = 0&
Public Function BroadcastMessage(sToUser As String, sFromUser As String, sMessage As String) As Boolean
Dim yToName() As Byte
Dim yFromName() As Byte
Dim yMsg() As Byte
Dim l As Long
yToName = sToUser & vbNullChar
yFromName = sFromUser & vbNullChar
yMsg = sMessage & vbNullChar
If NetMessageBufferSend(ByVal 0&, yToName(0), ByVal 0&, _
yMsg(0), UBound(yMsg)) = NERR_Success Then
BroadcastMessage = True
End If
End Function
Private Sub Command1_Click()
Dim x As Boolean
x = BroadcastMessage(TxtTo.Text, TxtFrom.Text, TxtMsg.Text)
If x Then
MsgBox "Message Sent"
Else
MsgBox "Message Not Sent"
End If
End Sub
any body please help me
Mohan G
|
|
|
|
|
hi there, basically i am new to VB.net and need a bit of help
i have a string like "Track 01 (2.33)". this string is an item of of a combo box
what i need to do is by clicking a button separating "Track 01" and put it in a list box and "2.33" in another list box...
can you help me plaese?
|
|
|
|
|
I assume you know how to put the item into the list box.
to split the string you can you
String.Split or you can use Instr(), Left(),Mid(), and Right().
Dim pos As Integer
Dim lstr As String
Dim rstr As String
Dim str As String
str = "track 01 (2.33)"
pos = InStr(str,"(")
If pos <> 0 Then
lstr = Left(str,pos)
rstr = Right(str,Len(str)-pos)
good luck
|
|
|
|
|
I am a newbie programing with VB.NET. I need to write an app separating Data Access Layer and form. In my DAL I have the following method:
Public Function GetcboRelationsDataSet() As cboRelationsDataSet
Dim ds As New cboRelationsDataSet
Try
cboRelationsDataAdapter.Fill(ds)
return ds
Catch exc As Exception
Dim msg As String
msg = "Error reading Widget List from database"
Throw New DALException(msg, exc, Nothing)
End Try
End Function
And in my form this code to bind the dataset:
Private Sub frmListeRelations_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rh As New RelationsHandler
Try
lstRelations.DataSource = rh.GetcboRelationsDataSet
lstRelations.DisplayMember = "sNom"
lstRelations.Refresh()
Catch ex As Exception
End Try
End Sub
Is this correct ? The code runs fine but no data comes up.
jean-luc
|
|
|
|
|
I’m working on a project which is designed to collect data (a LOT of data) from the user and store it in a database. In VB6 I probably would have used multiple forms (I’m still just learning though) but with VB.NET it seems more practical to use one form with multiple userControls and each userControl containing panels and each panel containing the necessary controls to collect the data.
My question is: Using a function under a btnNext, for example, how can I cycle through each of my panels?
Does anybody know of any good resources or examples that would illustrate this type of thing?
Thanks
Brad
|
|
|
|
|
Hi all,
I am facing a problem in a program of mine , i am designing a software that is tracking the users activities in IE , it matches the users url requests with an internal db of restricted urls and if found can close the IE , but the problem is reading the content in the address bar makes the IE close even from the IE cache ,, i want to allow the url to remain i the cache and the user can type it in the address bar as well (previously i was blocking as soon as the user was typing it.) but when the user hits the enter key or url i want to block it. Problem is how i know or trap whether the page has started to load or the IE has load it.I want to block it on request. How i do that .. Please advice ...
Thanks in advance ...
Sohel
Sohel Shaheen Mallik
Tathya Dot Com Pvt. Ltd.
Junior Programmer
Kolkata , 700059
+9103325734224(O)
+9103325738041(O)
+9103422530913(R)
---------------------
It Goes On !!
|
|
|
|
|
I have a VB project that contains a number of controls. The project is called Controls and one of the controls for example is called Label. So when used in another project the control type name is Controls.Label. Fair enough.
I have reimplemented the Controls library containing the controls in ATL keeping all the original GUIDS, IIDs and names to maintain compatibility. But VB insists on appending Ctl to my name, making it 'ControlsCtl.Label'. This makes the orginal VB form fail to load.
Any ideas?
|
|
|
|
|
Hi folks, I got a simple question! How do I make .NET menu look flat like VS. I succeeded in reproducing all but the flatness, it seems that the menu control always follows up my OS (Win200). Here is the function I use to draw my menu items, what am I missing. Please help me out I need it to complete a release (on a no royalty product). Thanks
No mather wahat I do my menu still look like 2000 with the .NET feel.
------------------------------------------------------------------------
Sub DrawItems(ByVal EvDrawItems As System.Windows.Forms.DrawItemEventArgs, _
ByVal Mi As MenuItem, _
ByVal m_Icon As Icon)
Dim br As Brush
Dim fDisposeBrush As Boolean
Dim img As Image
Dim br2 As New SolidBrush(Color.Silver)
Dim iSelFac As Integer = 0
Dim imgblk As Image
img = GetIconFromMapping(Mi)
EvDrawItems.DrawBackground()
EvDrawItems.Graphics.FillRectangle(br2, EvDrawItems.Bounds)
EvDrawItems.Graphics.FillRectangle(m_SideBarBrush,
EvDrawItems.Bounds.Left,
EvDrawItems.Bounds.Top, 24, 26)
If CBool(EvDrawItems.State And DrawItemState.Selected) Then
iSelFac = 1
End If
If Not img Is Nothing Then
imgblk = img
If CBool(EvDrawItems.State And DrawItemState.Selected) Then
Dim GDI As New GDI_Filters.Filters
GDI.GrayScale(imgblk)
EvDrawItems.Graphics.DrawImage(img, (EvDrawItems.Bounds.Left _
+ 6), _
(EvDrawItems.Bounds.Top + 6))
End If
EvDrawItems.Graphics.DrawImage(img, (EvDrawItems.Bounds.Left + 6) - iSelFac, _
(EvDrawItems.Bounds.Top + 6) - iSelFac)
If Mi.Checked Then
If (m_CheckImage <> -1) Then
EvDrawItems.Graphics.DrawImage(m_Icons.Images(m_CheckImage), (EvDrawItems.Bounds.Left + 6) - iSelFac, _
(EvDrawItems.Bounds.Top + 6) - iSelFac)
Else
EvDrawItems.Graphics.DrawImage(m_frmDummy.ImageList1.Images(0), (EvDrawItems.Bounds.Left + 6) - iSelFac, _
(EvDrawItems.Bounds.Top + 6) - iSelFac)
End If
End If
Else
If Mi.Checked Then
If (m_CheckImage <> -1) Then
EvDrawItems.Graphics.DrawImage(m_Icons.Images(m_CheckImage), (EvDrawItems.Bounds.Left + 6) - iSelFac, _
(EvDrawItems.Bounds.Top + 6) - iSelFac)
Else
EvDrawItems.Graphics.DrawImage(m_frmDummy.ImageList1.Images(0), (EvDrawItems.Bounds.Left + 6) - iSelFac, _
(EvDrawItems.Bounds.Top + 6) - iSelFac)
End If
End If
End If
Dim rcBk As Rectangle = EvDrawItems.Bounds
rcBk.X += 24
If CBool(EvDrawItems.State And DrawItemState.Selected) Then
br = New LinearGradientBrush(EvDrawItems.Bounds, Color.FromArgb(40, Color.Blue), Color.FromArgb(40, Color.Blue), 0)
fDisposeBrush = True
EvDrawItems.Graphics.FillRectangle(br, EvDrawItems.Bounds.Left + 2, rcBk.Top + 2, EvDrawItems.Bounds.Width - 4, rcBk.Height - 2)
ControlPaint.DrawBorder3D(EvDrawItems.Graphics, EvDrawItems.Bounds.Left + 2, rcBk.Top + 2, EvDrawItems.Bounds.Width - 4, rcBk.Height - 2, Border3DStyle.Flat)
End If
If fDisposeBrush Then br.Dispose()
br = Nothing
Dim sf As StringFormat = New StringFormat
sf.HotkeyPrefix = HotkeyPrefix.Show
sf.SetTabStops(60, New Single() {0})
If Mi.Enabled Then
br = New SolidBrush(Color.Black)
Else
br = New SolidBrush(Color.Gray)
End If
If (Mi.Text <> "-") Then
EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _
EvDrawItems.Bounds.Left + 26, _
EvDrawItems.Bounds.Top + 6, sf)
Else
EvDrawItems.Graphics.DrawLine(New Pen(Color.Gray), rcBk.Left, rcBk.Top + 2, rcBk.Width - 4, rcBk.Top + 2)
End If
If (Mi.Index = 0) Then
ControlPaint.DrawBorder3D(EvDrawItems.Graphics, EvDrawItems.Bounds.Left, EvDrawItems.Bounds.Top, EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Height, Border3DStyle.Flat, Border3DSide.Top Or Border3DSide.Left Or Border3DSide.Right)
Else
If Not (Mi.Parent Is Mi.GetMainMenu) Then
If (Mi.Parent.MenuItems.Count - 1 = Mi.Index) Then
ControlPaint.DrawBorder3D(EvDrawItems.Graphics, EvDrawItems.Bounds.Left, EvDrawItems.Bounds.Top, EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Height, Border3DStyle.Flat, Border3DSide.Bottom Or Border3DSide.Left Or Border3DSide.Right)
Else
ControlPaint.DrawBorder3D(EvDrawItems.Graphics, EvDrawItems.Bounds.Left, EvDrawItems.Bounds.Top, EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Height, Border3DStyle.Flat, Border3DSide.Left Or Border3DSide.Right)
End If
Else
If (Mi.GetMainMenu.MenuItems.Count - 1 = Mi.Index) Then
ControlPaint.DrawBorder3D(EvDrawItems.Graphics, EvDrawItems.Bounds.Left, EvDrawItems.Bounds.Top, EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Height, Border3DStyle.Flat, Border3DSide.Bottom Or Border3DSide.Left Or Border3DSide.Right)
Else
ControlPaint.DrawBorder3D(EvDrawItems.Graphics, EvDrawItems.Bounds.Left, EvDrawItems.Bounds.Top, EvDrawItems.Bounds.Width, EvDrawItems.Bounds.Height, Border3DStyle.Flat, Border3DSide.Left Or Border3DSide.Right)
End If
End If
End If
br.Dispose()
br = Nothing
sf.Dispose()
sf = Nothing
End Sub
The warlord
|
|
|
|
|
Hi!
If it's possible, how do I remove scrollbar from tree view control?
(Done it with data grid, but tree view seems to contain no other controls)
/Rickard
|
|
|
|
|
Hello Friends, Please give me ideas on how to carry on my project. What software can I possibly use?
This is the requirement for my final yr project:
Project Title: E-commerce website design: shopping cart
Aim of project: A commercial website needs to develop a shopping cart for their online shop
Summary of work to be undertaken:
*investigate a current state of e-commerce technologies
*propose a basic plan of your design
* implement the design into a fully functional shopping cart
*implement a simple web page to show how to use your shopping cart.
*Write a report and present the final result
=======================
I would be extremely grateful if you could advise me on the right programs to use.Please send your responses to dubeben2002@yahoo.co.uk
|
|
|
|
|