|
If I use the System.IO namespace to edit files where is the file default location. Will it be in the projects \bin directory?
|
|
|
|
|
Environment.CurrentDirectory or System.IO.Directory.GetCurrentDirectory() will provide you with the current working directory for your application.
Paul Marfleet
|
|
|
|
|
The default "current directory" is the folder you launched the .EXE from. BUT!! NEVER, and I mean NEVER, depend on the "current directory" to stay set to what you think it is. Your code should always build fully qualified path names to files.
|
|
|
|
|
i want vb6 code to enumerate installed devices
vimlesh
|
|
|
|
|
Noone is going to write it for you if that's what you're looking for.
Other than that, you'll have to ask a specific question about what you want. Somehow, I don't think you know anything about Windows Setup API functions.
|
|
|
|
|
I'm trying to do some Powerpoint automation from an ASP.NET page and generate/modify a slide. That piece of the code works fine but when it's all done running and even after I call the Quit() method on the powerpoint application object, POWERPOINT.EXE remains running and eventually this is causing problems. I've googled this extensively and nothing I've found has seemed to help. I really need this to work properly.
Here's my relevant code. I don't believe i'm using any Global references and I've even removed the COM reference from my website to use Late Binding instead in hopes that it would solve my problems as mentioned in this MSDN Article: http://support.microsoft.com/default.aspx?scid=kb;en-us;319832
Code:
Public Function GenerateDrillDown(ByVal strFileName As String) As Boolean
Dim App As Object = Nothing
Dim pres As Object = Nothing
Dim slide As Object = Nothing
Try
App = CreateObject("PowerPoint.Application")
App.Visible = -1 ' For debugging. Comment this out or set to 0 to keep the application from being visible.
pres = App.Presentations.Open("C:\DevProjects\Docs\DrillDown.ppt", 0, -1, -1)
slide = pres.Slides(1) ' There's only one slide in this ppt i'm using as the template.
slide.Shapes.Item("Text Box 8").TextFrame.TextRange.Text = DecisionTitle ' These are all string variables
slide.Shapes.Item("Text Box 13").TextFrame.TextRange.Text = Narrative
slide.Shapes.Item("Text Box 14").TextFrame.TextRange.Text = Issues
slide.Shapes.Item("Text Box 19").TextFrame.TextRange.Text = Scope
If TopicType = 1 Then
slide.Shapes.Item("Autoshape 9").TextFrame.TextRange.Text = IDNumber.ToString()
slide.Shapes.Item("Autoshape 9").Visible = -1
slide.Shapes.Item("Autoshape 56").Visible = 0
ElseIf TopicType = 2 Then
slide.Shapes.Item("Autoshape 56").TextFrame.TextRange.Text = "ST" & IDNumber.ToString()
slide.Shapes.Item("Autoshape 56").Visible = -1
slide.Shapes.Item("Autoshape 9").Visible = 0
End If
pres.SaveAs(strFilename, 1, 0)
Catch ex As Exception
Return False
Finally
' Most of this is coming from another article I found online to help combat the problem of open references with office automation.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect() ' Intentionally repeated
GC.WaitForPendingFinalizers()
If Not slide Is Nothing Then
Marshal.FinalReleaseComObject(slide)
slide = Nothing
End If
If Not pres Is Nothing Then
pres.Close()
Masrhal.FinalReleaseComObject(pres)
pres = Nothing
End If
If Not App Is Nothing Then
App.Quit() ' This doesn't do anything, no errors but ap stays open
Marshal.FInalReleaseComObject(App)
App = Nothing
End If
End Try
Return True
End Function
Please give me some guidance as this is an important piece of functionality required by my project. Thanks!
|
|
|
|
|
|
i have a windowform with employee image, Firstname and other data. I can save the image of the employee(when loaded into the image control) but when i dont load the picture in the image control it flags error
t.aransiola
|
|
|
|
|
And the error would be ...??? What about the code that's throwing it??
You only use a PictureBox to show an image, not to store it. And I'm not real thrilled with the idea of even using a PictureBox in most cases.
You do NOT do something like this:
PictureBox1.Image.Save...
|
|
|
|
|
instead of saving a blank picture box why not save a default image such as the company logo or such like. you can trap the error then load the default picture on this error.
|
|
|
|
|
Iwant the Image Field remain Null for those that doesnt have picture. saving a default image in the database will impact the db
thanks
t.aransiola
|
|
|
|
|
The picturebox should be there to show a picture, not to store one. If the database doesn't have a picture, you can either choose set the PictureBox's Image property to Nothing, or you can show a blank image or silohette image.
It appears you already have a picture in an Image object. After all, you have to set the PictureBox's image property to it so it shows up. So, you can save the image data to your database from the original image object, without using any of the properties of the PictureBox.
|
|
|
|
|
I have a MDI WIndow with treeview on the left,listview on the right with a splitter separating them
I want to open my other forms at a particular cordinate but its not working. i did something like this
dim myForm as New Invoice
myForm.left = listview.left
myForm.top=listview.top
myForm.show
the form wasnt positioned at where iwant it to be
pls help
t.aransiola
|
|
|
|
|
You used the coordinates of the listview, which are relative to it's parent container, not the screen.
So, the form being contained by nothing, used the coordinates relative to the desktop, not a window in your application.
|
|
|
|
|
pls assist with code snippet.
The listview is on Mdimain window. Now i want the other windows cordinattes to be using the listview cordinates
how do i get an object's reference cordinates in vb.net
t.aransiola
|
|
|
|
|
aransiola wrote: The listview is on Mdimain window. Now i want the other windows cordinattes to be using the listview cordinates
Since you haven't said anything about the parent container for this second form, I'm assuming you're not setting a parent window for the form. All you have to do is map the location of the ListView to Screen coordinates and use that result as the location for the new form.
Dim newLocation As Point = ListView1.PointToScreen(ListView1.Location)
Dim newForm As New Form2()
newForm.Location = newLocation
|
|
|
|
|
I ran into something simular last year and I think the problem was that you have to 'show' the form before setting the borders:
aransiola wrote: dim myForm as New Invoice
myForm.show
myForm.left = listview.left
myForm.top=listview.top
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
The code as shown below worked for non-modal window form
but did not position modal window forms. even setting the cordinates before showing the window form
dim myForm as New Invoice
myForm.show
myForm.left = listview.left
myForm.top=listview.top
any further discoveries to positioning modal forms will be appreciated.
thanks
thank u
t.aransiola
|
|
|
|
|
Hi,
I got a downloader program form internet but it was made in C# . I converted it to VB.NET . There is no errors in the code , but it isn't working ! Here is the few code form the whole project which is not working:
Imports System.IO<br />
Imports System.Net<br />
Imports System.Text<br />
Imports System<br />
Imports System.Collections.Generic<br />
Imports System.ComponentModel<br />
Imports System.Data<br />
Imports System.Drawing<br />
<br />
Imports System.Windows.Forms<br />
<br />
Imports System.Threading<br />
Public Class Download<br />
Private thrDownload As Thread<br />
' The stream of data retrieved from the web server<br />
Private strResponse As Stream<br />
' The stream of data that we write to the harddrive<br />
Private strLocal As Stream<br />
' The request to the web server for file information<br />
Private webRequest As HttpWebRequest<br />
' The response from the web server containing information about the file<br />
Private webResponse As HttpWebResponse<br />
' The progress of the download in percentage<br />
Private Shared PercentProgress As Integer<br />
' The delegate which we will call from the thread to update the form<br />
Private Delegate Sub UpdateProgessCallback(ByVal BytesRead As Int64, ByVal TotalBytes As Int64)<br />
' When to pause<br />
Private goPause As Boolean = False<br />
Private Sub Download(ByVal startPoint As Object)<br />
Try<br />
<br />
Dim startPointInt As Integer = Convert.ToInt32(startPoint)<br />
' Create a request to the file we are downloading<br />
webRequest = DirectCast(Net.WebRequest.Create("http://dl.google.com/picasa/picasaweb-current-setup.exe"), HttpWebRequest)<br />
' Set the starting point of the request<br />
webRequest.AddRange(startPointInt)<br />
<br />
' Set default authentication for retrieving the file<br />
webRequest.Credentials = CredentialCache.DefaultCredentials<br />
' Retrieve the response from the server<br />
webResponse = DirectCast(webRequest.GetResponse(), HttpWebResponse)<br />
' Ask the server for the file size and store it<br />
Dim fileSize As Int64 = webResponse.ContentLength<br />
<br />
' Open the URL for download <br />
strResponse = webResponse.GetResponseStream()<br />
<br />
' Create a new file stream where we will be saving the data (local drive)<br />
If startPointInt = 0 Then<br />
strLocal = New FileStream("C:\", FileMode.Create, FileAccess.Write, FileShare.None)<br />
Else<br />
strLocal = New FileStream("C:\", FileMode.Append, FileAccess.Write, FileShare.None)<br />
End If<br />
<br />
' It will store the current number of bytes we retrieved from the server<br />
Dim bytesSize As Integer = 0<br />
' A buffer for storing and writing the data retrieved from the server<br />
Dim downBuffer As Byte() = New Byte(2047) {}<br />
<br />
' Loop through the buffer until the buffer is empty<br />
While (bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0<br />
' Write the data from the buffer to the local hard drive<br />
strLocal.Write(downBuffer, 0, bytesSize)<br />
' Invoke the method that updates the form's label and progress bar<br />
' Me.Invoke(New UpdateProgessCallback(Me.UpdateProgress), New Object() {strLocal.Length, fileSize + startPointInt})<br />
<br />
If goPause = True Then<br />
Exit While<br />
End If<br />
End While<br />
Finally<br />
' When the above code has ended, close the streams<br />
strResponse.Close()<br />
strLocal.Close()<br />
End Try<br />
End Sub<br />
<br />
<br />
<br />
End Class<br />
Any suggestions will be thankful.
Dan.
|
|
|
|
|
Unlike C#, VB.NET doesn't allow variable assignment within a While loop header. You should modify your code to take account of this language difference.
Paul Marfleet
|
|
|
|
|
First, please use the <pre> tags when posting large snippets of code. It helps keep the formatting and makes it much easier to read.
Secondly, why are you converting the code? If the original project was written properly, you should be able to include the C# project in your solution or compile it separately and include the reference in your VB project to the DLL.
There are already several file downloader components here on CP that I know will work with VB code in the manner I describe above. You can check out this one[^] as a start.
|
|
|
|
|
Scott Dorman wrote: First, please use the "pre" tags when posting large snippets of code. It helps keep the formatting and makes it much easier to read.
Sorry , I was my mistake .:->
You suggested the perfect suggestion. Thanks.
|
|
|
|
|
Dan`M wrote: Sorry , I was my mistake
No problem. Just wanted to let you know for the future.
Dan`M wrote: You suggested the perfect suggestion. Thanks.
You're welcome.
|
|
|
|
|
Hi.I'm David Dlaka.
The Problem
Im making a projet with text files.There is a textbox in which you type some text.There are 3 buttons.Save,Open and Close.I'm having problem with the Save function.When you click save,an inputbox pops out and you need to type a code in it,so your files are secured.In the programming code the saving code is defined as "Short" ,but when i save it says:"Cast from string "mycode" to type 'Short' is not valid".Even if i change short with long,string integer or similar,it says tthe same thing!What do i do?
The code
This is the whole code
PrivateSub mnuSaveAsItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles mnuSaveAsItem.Click<br />
Dim letter As Char Dim lngCode As Short <br />
Dim i, charsInFile As Long <br />
Dim Code As Short <br />
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"<br />
SaveFileDialog1.ShowDialog()<br />
If SaveFileDialog1.FileName <> "" Then <br />
lngCode = InputBox("Insert code to code the file.")<br />
If lngCode = "" Then Exit Sub <br />
Code = charsInFile = Txtnote.Text.Length<br />
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)<br />
letter = Txtnote.Text.Substring(i, 1)<br />
Print(1, Asc(letter) <br />
CShort(lngCode)For i = 0 To charsInFile - 1Xor Code)Next <br />
FileClose(1)<br />
mnuCloseItem.Enabled = True End If End Sub Private Sub mnuCloseItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCloseItem.ClickDim a As String <br />
a = InputBox("Did you save?")<br />
If a = ("Yes") Or a = ("yes") Then <br />
Txtnote.Text = ""<br />
ElseIf a = ("No") Or a = ("no") Then <br />
MsgBox("Don't forget to save your file first")<br />
Else <br />
MsgBox("Please answer with ""Yes"" or ""No""")<br />
End If <br />
End Sub <br />
Private Sub mnuOpenItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpenItem.ClickDim CelTekst, LinijaNaTekst As String Dim lngCode As Short <br />
OpenFileDialog1.Filter = "Text files (*.TXT)|*.TXT"<br />
OpenFileDialog1.ShowDialog()<br />
Dim Code As Short If OpenFileDialog1.FileName <> "" Then Try <br />
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)<br />
LinijaNaTekst = LineInput(1)<br />
CelTekst = CelTekst & LinijaNaTekst & vbCrLf<br />
Do Until EOF(1)Loop <br />
Txtnote.Text = CelTekst<br />
Txtnote.Select(1, 0)<br />
Txtnote.Enabled = True <br />
mnuCloseItem.Enabled = True Catch <br />
MsgBox("Error with opening the file.")<br />
Finally <br />
FileClose(1)<br />
End Try <br />
End If <br />
End Sub Plese tell me what is wrong???
David Dlaka
|
|
|
|
|
Your code is really difficult to understand. You should modify your message and use <pre> tags to format the code to make it readable.
Paul Marfleet
|
|
|
|