|
I think that you can use the CopyTo method to copy the array into a byte array with a single element.
---
single minded; short sighted; long gone;
|
|
|
|
|
The BitArray class doesn't support conversions to other types (EDIT: I completely forgot about CopyTo!!).
If you're only using 8 bits, you're much better off just using a Byte and doing the bit manipulation yourself. It's easy to write your own methods to automate some of this, like setting or resetting a bit.
A quick little whip up:
Public Shared Function SetBit(ByVal value As Byte, ByVal position As Integer) As Byte
If position < 1 Or position > 8 Then
Throw New ArgumentOutOfRangeException("Position must be between 1 and 8.")
End If
Dim mask As Byte = CByte(2 ^ (position - 1))
If Not value And mask Then
value = value Or mask
End If
Return value
End Function
-- modified at 13:06 Wednesday 2nd May, 2007
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
hi there,
i made an application like notepad and i want when i click on any text file then my application should start so i select my application in open with and i coded in form1_load of my application
Dim newLine As String = ""
Dim cmdLine As String
open.InitialDirectory = System.Environment.SpecialFolder.Desktop
If InStr(System.Environment.CommandLine, ".txt") Then
cmdLine = System.Environment.CommandLine
Dim charInLine As String
Dim quoteCharStop As Integer = 0
Dim placeInString As Integer = cmdLine.Length - 1
While quoteCharStop < 2 And placeInString > 0
charInLine = cmdLine.Substring(placeInString, 1)
If charInLine = Chr(34) Then
quoteCharStop = quoteCharStop + 1
Else
newLine = charInLine & newLine
End If
placeInString = placeInString - 1
End While
Try
If File.Exists(newLine) Then
Dim o As StreamReader = File.OpenText(newLine)
Text1.Text = o.ReadToEnd()
o.Close()
End If
Text1.SelectionStart = 0
Text1.SelectionLength = 0
Catch
End Try
savechk = False
End If
its working but when i open large file the application appear blank(i.e. rich text box blank)
someone know the solution??
i also want to code a button as when i click on then it should change open with program to mine application
|
|
|
|
|
Well, your code is looking for ".txt" on the command line. That's a bad assumption to make. If should just open the file it's given, no matter what the extension is. You're also trying to parse up the command line when you really don't have to. There's a method on the Environment class that returns al the command line arguments already parsed up:
Dim args As String() = Environment.GetCommandLineArgs()
If args.Length > 1 Then
' There's at least one argument, besides our .EXE filename
' Treat the first argument as a filename and try to open it as text file.
LoadFile( args(1) )
End If
.
.
Private Sub LoadFile(ByVal filepath As String)
Try
If File.Exists(filepath) Then
Text1.Text = File.ReadAllText(filepath)
Else
Throw New FileNotFoundException(String.Format("The filepath {0} was not found!", filepath))
End If
Catch ex As Exception
' Not exactly "good practice", but this works for this example...
Throw ex
End Try
End Sub
Now, if you're using a RichTextBox, there is no maximum size of text that can be read. If you're using a TextBox, you might want to check the MaxLength property and set it to 0 to indicate that there is no limit to maximum length of text in the box.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
hey thanks, its working, thats really good i did alot of coding to get that path ,i also tried Environment.GetCommandLineArgs() but i didnt knew what is this and how to use it?
to open text files i always use rich textbox because it have more functions than textbox
1 question::
i didnt understand that how the value\file path come in this variable(filepath)...????
Private Sub LoadFile(ByVal <code>filepath</code> As String)
buddy i have another question thst is
when i click on a button then it should change open with program to mine application
|
|
|
|
|
xmen_xwk wrote: i didnt understand that how the value\file path come in this variable(filepath)...????
Private Sub LoadFile(ByVal filepath As String)
This is what the calling code has to pass into this method. Seriously, if you're asking this question, you really need to pickup a book on VB.NET for Beginners. This is 2nd day of class stuff.
xmen_xwk wrote: when i click on a button then it should change open with program to mine application
This is done outside of your application, normally by the installer for your application.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
oh yeah but i couldn`t see that line properly where the calling code....
and to change 'open with' program then i want to know how to do that?
|
|
|
|
|
Hi,
I'm just adding (another) final piece to my app which involves printing. Okay, not much fun but, been there before and bought the T-shirt.
Okay, it seems to work, I'm printing exactly what I expect to see on an HP LaserJet.
I've got a PrintDialog component to allow me to select the printer. I select a second printer, Epson,(rather than the default HP) and all I get is a pile of blank pages. Have to cancel the document, turn off the printer and wait 5 minutes.
If I swap the default printer to the Epson, same thing happens on that printer but I can use the PrintDialog to select the HP which as before, works fine. So the PrintDialog appears to be working.
Stepping through the PrintDocument method, the strings being "printed" appear to contain the correct data - in short, the method looks to be doing exactly what it should (as it must, as I can print on the HP).
Print preview works fine whichever printer is selected.
When the Epson is reset, I can print a test page okay from Word.
So, to summarise:
1) The Epson printer works
2) The PrintDocument1.Print method works
3) The Printdialog works
4) The Print preview works.
So why can't I print on the damn Epson?
Post script:
Another part of my project which has been tested to death, allows the selection of a printer. Just tried a test print with this and got the same thing - endless blank pages on the Epson. The code here has not been changed and used to work fine.
Any ideas anyone?
Cheers,
Rich
|
|
|
|
|
Odd. Is the Epson printer setup with a text only driver?
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
No it's not. As it happens, I'm only printing text anyway.
I have had an Epson printer behave strangely in the past but turning it off and re-starting Windows has always worked in the past. Not this time.
May turn everything off for half an hour and try again as I can't see anything to indicate that the App is at fault.
Cheers,
Rich
|
|
|
|
|
I've partly solved it!
Just realised that the printer I was selecting isn't the model installed - it's one we don't use anymore and the model numbers are so similar I didn't realise.
However, this fails to explain why the Dialog box fails to pick up the real printer that is attached and works from other apps!!
Rich
|
|
|
|
|
Hi can any one tell me how to show only one open window of the application even if it contains multiple windows.
Example i have 5 forms in the project and when i open the form while running it shows multiple opened windows on the taskbar, where as i need only 1.
Jats
|
|
|
|
|
If you go to the design view of your form theres a ShowInTaskbar Option, set it to False for the Forms you dont want to show in the Taskbar.
" In the next millennium there are two kinds of business, those on the Internet and those out of business"
Bill Gates
"Be nice to nerds. Chances are you'll end up working for one."
Bill Gates
"Let's face it, the average computer user has the brain of a Spider Monkey."
Bill Gates
|
|
|
|
|
Have you seen the ShowInTaskbar property of the Form class?
Dim newForm As New Form2
newForm.ShowInTaskbar = False
newForm.Show()
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
hi jats
First u decide which form's title must be show in task bar .
if u want to show same form title for all condition, then change the property ShowInTaskBar to false for all other remaining form.
and if u want to show different title for different form at the base of active form(but have only one window in task bar) then set ShowInTaskBar property to false for all other form at load event of present active form.
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Hi there,
I have a VB MFC that uses a dll for sending, receiving, dispalying and logging data from/to another application the problem is that SOMETIMES when I close the VB window by clicking on X the application goes off ( you do not see it on desktop) but when you open the task manager, you can see that the application is still there. The problem is that it happens just sometimes. Any ideas?
It is the way I close the appliaction:
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Are you sure you want to Exit the application?", vbYesNo + vbQuestion, "Application") = vbNo Then
Cancel = True
End If
End Sub
Private Sub MDIForm_Terminate()
fnWEHostShtdn
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
If Me.WindowState <> vbMinimized Then
SaveSetting App.Title, "Settings", "MainLeft", Me.Left
SaveSetting App.Title, "Settings", "MainTop", Me.Top
SaveSetting App.Title, "Settings", "MainWidth", Me.Width
SaveSetting App.Title, "Settings", "MainHeight", Me.Height
End If
End Sub
The other question is that how I can check if an application is running and if for any reason (even a hard close by user) the application is closed, it reopens itself.
Thanks in advanced.
Nahitan
|
|
|
|
|
This is usually caused by an improper shutdown of a component in your app. Most likely, this would be the .DLL you're using. It's possible that it created a seperate thread(s) that are still running when your app quits. You'll have to check with the docs or anything else you can find on this library and see if it needs you to do anything special to shut it down before your app closes.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks for the reply, but when you want purposely close the application, is it the VB application responsible for that or the dll application which is written in C++ and has many threads?
Thanks
|
|
|
|
|
Yes! Any .DLL you load becomes a part of your code, not a seperate process. This is a curious question, because throughout all coding, if your code creates or loads something, your code is also responsible for managing and destroying that something properly.
Making the assumption that an object or runtime can clean itself up without you telling it to do so is a very bad thing to do. This practice leads to unstable applications and operating systems. For instance, if you application creates a Graphics object, you are also responsible for destroying it when your done with it. If not, you'll eventually run the system out of resources and crash the whole operating system.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I need to call Outlook Compose mail box, By inserting subject and mail Id and show it to the user.
I can make it up to calling the outlook.exe but cannot call compose mail box directly.
Please help...
Jats
|
|
|
|
|
I'm not an expert but I use this:
<code>
Dim oOutlook As New Outlook.Application
Dim oMailitem As Outlook.MailItem
Dim oAttach As Outlook.Attachment
oMailitem = CType(oOutlook.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
oMailitem.To = "Jack <jack@isp.co.za>"
oMailitem.Subject = "Your Subject "
oMailitem.Body = "Hello, "
oMailitem.Display()
'oMailitem.Send()
</code>
I take it you already have references to Outlook.
Hope it helps
|
|
|
|
|
Thankx a lot for your help!!!
The code is perfect...i did it before but missed a line
Can you please tell me how to add multiple lines in the body, One line after the other, should i use some thing like or \n.
Jats
|
|
|
|
|
Hi dont mind i got it.
Thankx again!!!
Jats
|
|
|
|
|
hi jats use following code
pass required argument to following function
Function MailComponent(ByVal mailTo As String, ByVal cc As String, ByVal Bcc As String, ByVal subject As String,byval bodyofMessage as string)
Dim str, body As String
str = ""
If bodyofMessage Is Nothing Then
body = bodyofMessage
End If
If cc Is Nothing Then
cc = ""
End If
If Bcc Is Nothing Then
Bcc = ""
End If
If subject Is Nothing Then
subject = ""
End If
'string builder used for concatination
Dim MsgBuilder As New System.Text.StringBuilder
MsgBuilder.Append("mailto:" & mailTo)
If Not cc.Trim = "" Then
MsgBuilder.Append("&cc=" & cc)
End If
If Not Bcc.Trim = "" Then
MsgBuilder.Append("&bcc=" & Bcc)
End If
If Not subject.Trim = "" Then
MsgBuilder.Append("&subject=" & subject)
End If
If Not Body.Trim = "" Then
MsgBuilder.Append("&body=" & Body)
End If
If Not Attachment.Trim = "" Then
MsgBuilder.Append("&Attach=" & Attachment)
End If
'Debug.WriteLine(MsgBuilder.ToString)
ExecuteFile(MsgBuilder.ToString)
End Function
Function ExecuteFile(ByVal FileName As String) As Boolean
Dim myProcess As New Process
myProcess.StartInfo.FileName = FileName
myProcess.StartInfo.UseShellExecute = True
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.Start()
myProcess.Dispose()
End Function
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Thankx for the help, i got it.
Jats
|
|
|
|