|
Imports System.IO
Imports System.Text
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(8, 8)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(120, 199)
Me.ListBox1.TabIndex = 1
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(144, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(192, 200)
Me.RichTextBox1.TabIndex = 2
Me.RichTextBox1.Text = "RichTextBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(352, 230)
Me.Controls.Add(Me.RichTextBox1)
Me.Controls.Add(Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("This")
ListBox1.Items.Add("Is")
ListBox1.Items.Add("A")
ListBox1.Items.Add("Way")
ListBox1.Items.Add("This")
ListBox1.Items.Add("Can")
ListBox1.Items.Add("Work")
RichTextBox1.Clear()
End Sub
Private Sub GetFiles(ByVal di As DirectoryInfo, ByVal searchPattern As String, ByRef MyFiles As ArrayList)
For Each fi As FileInfo In di.GetFiles(searchPattern)
MyFiles.Add(fi.FullName)
Next
For Each d As DirectoryInfo In di.GetDirectories()
GetFiles(d, searchPattern, MyFiles)
Next
End Sub
'this is the search and it is CASE Sensitive
'it searches for the first occurrence of the search word
'and records the path and filename in the richtextbox1
Private Function ReadMyFile(ByVal MyFilePath As String) As String
Dim MyStreamReader As StreamReader = IO.File.OpenText(MyFilePath)
Dim MySB As StringBuilder = New StringBuilder
Do While MyStreamReader.Peek() >= 0
MySB.Append(MyStreamReader.ReadLine())
Loop
Dim index As Integer = -1
Do
index += 1
index = MySB.ToString.IndexOf(ListBox1.SelectedItem, index)
If index >= 0 Then
RichTextBox1.AppendText(MyFilePath & vbCrLf)
Exit Do ' remove this to find all occurrences
End If
Loop Until index = -1
MyStreamReader.Close()
Return MySB.ToString()
End Function
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
RichTextBox1.Clear()
' files to search for
Dim searchPattern As String = "*.xml"
' directory to start recursive search in
Dim InitDirectory As String = "C:\xmldata\"
Dim MyFiles As ArrayList = New ArrayList
Dim di As DirectoryInfo = New DirectoryInfo(InitDirectory)
GetFiles(di, searchPattern, MyFiles)
For Each s As String In MyFiles
'Debug.WriteLine(s)
ReadMyFile(s)
Next
End Sub
End Class
|
|
|
|
|
I am attempting to convert a UTC time into a normal date and time using a dataset and the dataset's .GetXML() method.
I currently have the following UTC Time:
2004-08-16T16:30:54.0000000-05:00
I would like it to display as:
8/16/2004 4:30:54 PM
This is so that when I create an Excel file through XSLT, I can set the column type to Date and then have a date that is User Friendly.
Thanks for any help that can be provided.
|
|
|
|
|
Daytime, Internet Time Service Class
By Alastair Dallas
http://www.thecodeproject.com/vb/net/daytime.asp
|
|
|
|
|
hI ALL, My problem is this:
Im writting a control that reads a list of graphics from an embedded text file. This file is generated by soap formatter.
The Soap F. serialises a class that holds info.
My program then uses soap to deserialise the file, back into the orig class and reads the info and loads the embedded pictures into variables
This all works fine at runtime, but when you add the control to a form in design time it returns an error : Cast not valid.
I can Deserialise it back into a object type though.
i.e
Dim SoapF as new soapformatter
Dim MemoryStream as memoryStream
Dim obj as Object
Dim tstClass as TestClass
'This works at designtime/runtime :
obj = soapf.deserialise(MemoryStream,Object)
'This works at runtime (but i need it to work all the time!) :
tstClass = soapf.deserialise(MemoryStream,TestClass)
Any Ideas?
__________________
Thanks for your help!
|
|
|
|
|
I have a bitmap(.bmp) I want to read bitmap's 1st pixel or other pixels. How I read it? How I find pixel coordinate?
Is it possible on the vb6?
You should to visit this site. http://www.2ncielbilgisayar.com and http://www.crosscable.net
|
|
|
|
|
try here
http://www.vbaccelerator.com/home/VB/Code/vbMedia/Image_Processing/index.asp
|
|
|
|
|
|
I have to do something similar in file manger(like Norton Commander etc)in VB.Net and I need some free code for that cause I found big difficulties in building that.Anybody can help me?
|
|
|
|
|
Your going to have to be a bit more specific about what you're looking for. There's free code all over this site, but what do you need help with?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a reliable way to determine if any given path is on a local device, rather than a mapped or shared device? (I know I can scrape the string for C:, etc. but I want this to work even if the PC has several partitions.) Thanks.
Jerry
|
|
|
|
|
Jerry,
You could do somthing like this i suppose.
Imports System.Runtime.InteropServices
<DllImport("mpr.dll", SetLastError:=False, CharSet:=CharSet.Auto)> _
Friend Shared Function WNetGetUniversalName( _
ByVal lpLocalPath As String, _
ByVal dwInfoLevel As Int32, _
ByVal lpBuffer As IntPtr, _
ByRef lpBufferSize As Int32) As Int32
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bufSize As Int32 = 2000
Dim bufPtr As IntPtr = Marshal.AllocHGlobal(bufSize)
Dim sMapPath As String = "Z:\"
Dim ret As Int32 = WNetGetUniversalName(sMapPath, 2, bufPtr, bufSize)
If ret = 0 Then
Debug.WriteLine("This is a Mapped Network Drive " & ret)
End If
If ret = 1200 Then
Debug.WriteLine("The specified device name is invalid. " & ret)
End If
If ret = 2250 Then
Debug.WriteLine("This network connection does not exist. " & ret)
End If
Marshal.FreeHGlobal(bufPtr)
End Sub
|
|
|
|
|
Dang, I hate when it does that.
<DllImport("mpr.dll", SetLastError:=False, CharSet:=CharSet.Auto)> _
Friend Shared Function WNetGetUniversalName( _
ByVal lpLocalPath As String, _
ByVal dwInfoLevel As Int32, _
ByVal lpBuffer As IntPtr, _
ByRef lpBufferSize As Int32) As Int32
End Function
|
|
|
|
|
I am currently working on an application that reads in a file of around 450 lines. Each line of the file can vary in length and I need to modify either the third line or the fourth line in the file. The value at these lines are of type string but are read in and converted to integers. Once I handle the integer I write it back out as a string. The problem is that apparently in VB or VB.Net a file that can be read and written to has to be opened in random mode but then requires that each line be a specific size. I really need to handle the lines as they vary in length. Is there a way to read and write to the same file while it is open in random or some other mode! Thanks for any help!
DC9Pilot
|
|
|
|
|
You've just found the one reason to can't use text files as random access databases.
What you're going to have to do is rewrite the ENTIRE file in order to make this change. The quick way to do it is to read in the entire file, line by line, into an array of strings. Make the changes you want to the array, then write the file back out, overwriting the file that was there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave! I was afraid I'd have to do something like that.
|
|
|
|
|
I liked how the masktextbox in vb6 works. Is there anything similar to that in vb.net? I am pretty much trying to mask a phone number to make it
(###)###-####. Is this possible to do in vb.net?
This is what I am doing now:
txtHome.Text = Microsoft.VisualBasic.Left(strHome, 3) & "-" & Microsoft.VisualBasic.Mid(strHome, 4, 3) & "-" & Microsoft.VisualBasic.Right(strHome, 4) which produces ###-###-####. There has to be another way to do this. It is working this way but when I save back to the database, I have to unmask it(which I don't like). Please help.
Thanks
Beginner in ASP.Net and VB.Net
|
|
|
|
|
Well, there is no Masked Edit class in the .NET BCL. At least, not yet...
You can still use the Masked Edit control from VB6 though. If MSMASK32.OCX on your machine and registered, all you need to do is add it to the ToolBox.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
You can still use the Masked Edit control from VB6 though. If MSMASK32.OCX on your machine and registered, all you need to do is add it to the ToolBox.
I tried this and all seemed great but when I went to fill the masked edit control with text, it never displays any text. Is there something that I need to set or change in the control? The only thing I did was change the mask to (###)###-####, then filled it with text
txtNumber.Text = "1234567899". Nothing happens.
Any suggestions?
Thanks
|
|
|
|
|
That's because when you use the .Text property, the text entered must match the mask format exactly. If not, you won't see anything. You can't use the MaskedEdit control to format the data for you. You have to use the String.Format method for that.
Text Property (MaskedEdit Control)[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a way in vb.net code to find what the screen resolution on the clients machine is set to?
For example, I might want to place a form at a specific spot close to the bottom righthand side of the screen. To do this I change the location property. Unfortunately the bottom right corner changes depending on the screen size the client has setup or even changes to while using my app.
Any help is appreciated?
Lost in the vast sea of .NET
|
|
|
|
|
Check out the Screen class in the System.Windows.Forms namespace. It'll give you everything you need to get the dimensions you want. Just be aware that your application can be running on a multiple monitor desktop and must account for this. Use the PrimaryScreen property to return a Screen object that represents, obviously, the primary screen, the one most applications are displayerd on when launched.
An example:
' Retrieve the working rectangle from the Screen class
' using the PrimaryScreen and the WorkingArea properties.
Dim workingRectangle As System.Drawing.Rectangle = _
Screen.PrimaryScreen.WorkingArea
' Set the size of the form slightly less than size of
' working rectangle.
Me.Size = New System.Drawing.Size(workingRectangle.Width - 10, _
workingRectangle.Height - 10)
' Set the location so the entire form is visible.
Me.Location = New System.Drawing.Point(5, 5)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This worked great!!
Thanks!
Lost in the vast sea of .NET
|
|
|
|
|
well i need to set text for a combo and i dont want anyone else to be able to edit the text. Once some text has been selected the user can also be able to choose an item from the combo meaning i dont want the lock property. I've set the style to 0 and i can do the set text part but it is editable. When i set the combo style property to 2 then i cant set text in the combo. Any ideas what i am missing out on??
|
|
|
|
|
I'm confused... What exactly are you trying to do? A ComboBox, style = 2, would let you pick from the list, but not edit the text in the textbox. IIRC, you can set the text in the textbox through code, but only if the text matches an item in the list. So what's the goal here?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i need to select a particular text and the user should not be able to edit the combo box.
Thanks for the reply
|
|
|
|