|
Currently i am using the below coding to create a text file and write something on it..
Dim wfile As New System.IO.StreamWriter("c:\test.txt")<br />
wfile.WriteLine("Hello" & vbcrlf & "Are" & vbcrlf & "You")<br />
wfile.Close()
The text file content should be like this
Hello
Are
You
What if i want to insert "How" into the text file to modify the text file become like this..
Hello
How
Are
You
Anyone can provide the coding on how to get the specific line in a text file and insert lines of text into the text file?Any help is greatly appreciated... Thanks..
|
|
|
|
|
it can be done. i dont know how, tho..
i do know how to append text though.. that is, to add text to the end of a text file. i dont know how to go about inserting text onto the specific line/location into an existing file, sry. however if the appending text method is suitable, i can explain it.
------------------------
Jordan.
III
|
|
|
|
|
thanks for replying me.... can u tell me ur method how to append text as well? thanks for help..
|
|
|
|
|
Open the file for Append and start writing.
Dim myFile As New FileStream( "filename.txt", FileMode.Append )
myFile.WriteLine( "Text I want to append..." )
myFile.Close()
RageInTheMachine9532
|
|
|
|
|
You can't "insert" text without rewriting the file from the point where you are inserting. There are a couple of ways to do it:
1.) Seek to the point where you want to insert text, read the text from that point to the end of the file and store it. Seek back to the point where you want to insert text and write what you wanted to insert, then write everything you read in and stored previously. Done...
2.) Create a second file (text2.txt). Read everything from your original file (text1.txt), up to the point where you want to insert, and write it out to text2.txt. Write out what you want to insert. Then finished reading text1.txt and write everything out to text2.txt. Then delete text1.txt and rename text2.txt to text1.txt. Done...
RageInTheMachine9532
|
|
|
|
|
I want to add a section in my vb.net application to ask the client if they want to format a diskette or not. If they answer yes, go ahead and format a diskette in drive a:.
Does anyone have some code in Vb that will format a diskette?
Any Help is Appreciated
|
|
|
|
|
You could try using the Windows API SHFormatDrive() function -- here's a class that wraps it:
Public Class ShellUtilities
Public Declare Unicode Function SHFormatDrive _
Lib "Shell32.dll" _
(ByVal hwnd As IntPtr, _
ByVal iDrive As Int32, _
ByVal iFormatID As Int32, _
ByVal iOptions As Int32) As Int64
Public Const SHFD_CAPACITY_DEFAULT = 0 'default drive capacity
Public Const SHFMT_OPT_FULL = 1
Public Const SHFMT_OPT_SYSONLY = 2
Public Shared Sub FormatDrive(ByVal dialogOwner As IntPtr, ByVal iDrive As Int32)
SHFormatDrive(dialogOwner, iDrive, SHFD_CAPACITY_DEFAULT, SHFMT_OPT_FULL)
End Sub
End Class
And here's an example of calling it from a windows form button click:
Const A_Drive = 0
Const B_Drive = 1
Const C_Drive = 2
' ... etc ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShellUtilities.FormatDrive(Me.Handle, A_Drive)
End Sub
|
|
|
|
|
Try this:
Const SHFMT_ID_DEFAULT = -1
Const SHFMT_OPT_FULL = 1
Const SHFMT_OPT_SYSONLY = 2
Const SHFMT_ERROR = -1 ' Error on last format, drive may be formatable
Const SHFMT_CANCEL = -2 ' Last format was canceled
Const SHFMT_NOFORMAT = -3 ' Drive is not formatable
' SHFormatDrive takes 4 parameters:
' hWnd The handle to the window that will be the dialogs parent window.
' Drive The drive number to format, 0 is A:, 1 is B:, 2 is C:, ...
' fmtID Must always be SHFMT_ID_DEFAULT, or the value ????.
' options Opitons.
Private Declare Function SHFormatDrive Lib "shell32" ( _
ByVal hWnd As IntPtr, _
ByVal Drive As Integer, _
ByVal fmtID As Integer, _
ByVal options As Integer) _
As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iDrive As Integer
Dim rc As Integer
iDrive = 0
rc = SHFormatDrive(Me.Handle, iDrive, 0, 0)
Select Case rc
Case SHFMT_ERROR
MsgBox("Format failed, user pressed CLOSE")
Case SHFMT_CANCEL
MsgBox("Format cancelled - user hit CLOSE")
Case SHFMT_NOFORMAT
MsgBox("Unable to format this disk drive")
Case Else
MsgBox("Disk was formatted successfully and returned: " & rc)
End Select
End Sub
This will show the format dialog that you see when you do a format from the Explorer Shell. The format won't start until the user presses OK.
RageInTheMachine9532
|
|
|
|
|
Thank you very much for your feedback. I used the code that everyone submitted and it worked great!!
Is there a way to pass the Label that you want to use when formatting the diskette.
I found the SHFormatDrive documentation on MSDN, but I really don't see a way to pass a Label in.
Thanks again for the help,
Kevin
Lost in the vast sea of .NET
|
|
|
|
|
You can't pass that information to SHFormatDrive, but you can set the volume label after the disk is successfully formatted. You can use SetVolumeLabel, declared in kernel32, by passing in the root path of the drive, like A:\, and the name you want:
Private Declare Function SetVolumeLabel Lib "kernel32" _
Alias "SetVolumeLabelA" ( _
ByVal rootPath As String, _
ByVal newLabel As String) _
As Integer
Dim rc as Integer
rc = SetVolumeLabel( "A:\", "LabelTest" )
RageInTheMachine9532
|
|
|
|
|
Hy,
I want to make an apllication in vb.net that send's through the POST method the user and pass to the yahoo page and returns me into a text box the link to my inbox.
Any ideas.
Thanks.
|
|
|
|
|
Why should i use subclassing? I am not sure what it is for or how it is used. do you know where i can find an article about this subject?
Thnx,
Grtz,
Guus
|
|
|
|
|
Hi there. Subclassing is the act of deriving a new class by inheriting from an existing class. You would do this if you wanted to take advantage of functionality in the base class and add functionality of your own. For example, let's say you want a text box for your windows forms application, but one that accepts only numbers and ignores other characters typed from the keyboard. In most ways, you want your text box to behave just like a regular text box; you just want the additional functionality that limits keyboard entry to numbers only. You could create a subclass of the TextBox class by inheriting it, then override keyboard handling methods to insure that only numbers are allowed.
|
|
|
|
|
Well the subject says it all.
I believe that every object has a hWnd and using this hWnd you can color the background of a treeview or do all sorts of thing. Do you know where i can find an article about this?
Thnx,
Grtz,
Guus
|
|
|
|
|
gpa2000 wrote:
I believe that every object has a hWnd
Not true. every Window has a Window Handle. Individual controls are also windows and have a window handle. But not every element you see on the screen or every object in memory has a Window Handle.
gpa2000 wrote:
using this hWnd you can color the background of a treeview or do all sorts of thing
Uhhh...not exactly. The hWnd is the identifier for a Window that you can use to talk to the Window or other functions that take a hWnd as an input parameter. The Win32 API is FULL of funtions that use hWnd and not just for modifiying control properties. There isn't any one article that covers all the uses for Window Handles, but you can start here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows.asp[^]
RageInTheMachine9532
|
|
|
|
|
hello
i wish to know the coding
for the button
that perform opening either Internet Explore or Netscape
to a web address
i hope it wont be a trouble
thank you
Gary
|
|
|
|
|
In VB:
'<br />
' Procedure voor het opstarten van de default browser met een URL<br />
'<br />
' Zie Q224816, Q174156 voor meer informatie<br />
'<br />
Public Sub StartDefaultBrowser(ByVal strUrl As String)<br />
Dim lngReturnValue As Long<br />
<br />
lngReturnValue = ShellExecute(0, _<br />
"open", _<br />
strUrl, _<br />
0, _<br />
0, _<br />
SW_SHOWNORMAL)<br />
' Returnvalue <= 32 means error<br />
If (lngReturnValue <= 32) Then<br />
Err.Raise ERR_WARNING, FormatErrSource(MODULENAME, "CheckFields"), "Can't start default internet browser (" & CStr(lngReturnValue) & ")"<br />
End If<br />
<br />
End Sub
Grtz,
Guus
|
|
|
|
|
|
Can someone tell me how to print the text at the center of the paper?
i am using a receipt print with a maximum of 40 characters per line
Proper Planning is way to success
|
|
|
|
|
Since you know the width of the printer you pad the beginning of the string with spaces. Take the length of the line you want to print away from the width of the printer, then divide that difference by 2 to get the number of spaces to add on both sides of the test you want to print, but only add it to the beginning of the text:
Dim sText As String = "Text to print Centered"
Dim iPad As Integer
iPad = ( 40 - sText.Length ) / 2
sText = New String( Chr(32), iPad ) & sText
RageInTheMachine9532
|
|
|
|
|
New string is an unexperted identified. so how??
Proper Planning is way to success
|
|
|
|
|
Are you using VB6 or VB.NET?
The code sample works as advertised on VB.NET.
The equivelent code in VB6 would be this:
Dim sText As String
Dim iPad As Long
sText = "Text to print Centered"
iPad = ( 40 - Len(sText) ) / 2
sText = String$( iPad, 32 ) & sText
RageInTheMachine9532
|
|
|
|
|
Writing code using VB.net (aspx file)~ script assignment statement: set UserData = request.form("UserData") yields a compile error ~ 'Let' and 'Set' assignment statements no longer supported. Is there a substitute assignment statement that will work instead of 'Set' ?
Many thanks!
Reed Eichner
reichner@satx.rr.com
|
|
|
|
|
Yeah:
Dim UserData As String
UserData = Request.Form.Item("UserData")
RageInTheMachine9532
|
|
|
|
|
Hello,
Is there a way to create an entire Access database (I know what tables and the relationships needed between the tables) using VB code? For instance, if a user clicked on a "Create Plan" icon, the following database would be created in the back end:
Database: Census
Tables:
Client
Plan
Employees
Contacts
If you know of references you could direct me to in order to learn more about this, it would be greatly appreciated.
Thanks so much!
Vi
|
|
|
|