saving image from picturebox using savefile dialog problem please hep - vb.net

I have the following code in VB 2010:
'>>>>>CODE FOR SAVING THE CAPTURED IMAGE<<<<<
Private Sub btnSaveSpecimen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSpecimen.Click
'Saves the Image Captured
Dim Result As DialogResult 'variable declarations
Dim cap_image As Image
'opens a save dialog box for saving the settings
Result = savCaptured.ShowDialog
If Result = DialogResult.OK Then
cap_image = picSpecimen.Image
cap_image.Save(savCaptured.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
End Sub
When I run the program, the following error occurs
A generic error occurred in GDI+.
How can I resolve this?
please help me TYI

Most of the time when you encounter this error it's either one of two things. These are easy to rule out as the cause so you might want to consider doing that before looking elsewhere.
You attempt to write a file to a directory that you don't have Permission for.
You are trying to write back an image that you still have open.

Related

vb.net datetimepicker not taking value from my.setting

I have this code to save value from datetimepicker1:
Private Sub DateTimePicker1_Validating(sender As Object, e As EventArgs) _
Handles DateTimePicker1.Validating
My.Settings.dt1value= DateTimePicker1.Value.ToString
MsgBox("before save")
My.Settings.Save()
MsgBox("after save")
End Sub
It look that it saves value in My.Settings (From Message box 1,2)
Then when closing the app and running it again; it is not loading the My.Settings.dt1value into DateTimePicker1
The code for loading is:
Private Sub main_Shown(sender As Object, e As EventArgs) Handles Me.Shown
DateTimePicker1.Value = Convert.ToDateTime(My.Settings.dt1value)
End Sub
Other controls like Textbox1 is saving and loading properly but only for DateTimePicker is not working.
I tried to change from Handles Me.Shown to Handles Me.Load but same problem.
I have another problem,
When I deploy the application and setup in windows, My.Setting.Save() not working for all controls.
I had read other similar posts and try to follow them but nothing helps.
Any tip appreciated,
Thanks in advance.
First check whether the value is getting saved. Use
MsgBox(My.Settings.dt1value)
instead of
MsgBox("after save").
This will ensure the value is getting saved.
MsgBox("before save") & MsgBox("after save") does NOTHING useful here
But as from your code snippet, It seems the value is getting saved.
In the form Load event write the below mentioned code and check for the output:
string DatePattern = "dd/MM/yyyy HH:mm:ss";
DateTime ConvertedDateTime;
DateTimePicker1.Value = DateTime.TryParseExact(My.Settings.dt1value, DatePattern , null, DateTimeStyles.None, out ConvertedDateTime))
Edit : About your second problem
That is because whenever you update or modify the application in any way, the My.Settings(built-in settings file) gets flushed and a new one is generated. I would suggest you to save your config file in a separate external file. NOT in My.Settings

VB.net program hangs when asked to read .txt

I am attempting to read a .txt file that I successfully wrote with a separate program, but I keep getting the program stalling (aka no input/output at all, like it had an infinite loop or something). I get the message "A", but no others.
I've seen a lot of threads on sites like this one that list all sorts of creative ways to read from a file, but every guide I have found wants me to change the code between Msgbox A and Msgbox D. None of them change the result, so I'm beginning to think that the issue is actually with how I'm pointing out the file's location. There was one code (had something to do with Dim objReader As New System.IO.TextReader(FileLoc)), but when I asked for a read of the file I got the file's address instead. That's why I suspect I'm pointing to the .txt wrong. There is one issue...
I have absolutely no idea how to do this, if what I've done is wrong.
I've attached at the end the snippet of code (with every single line of extraneous data ripped out of it).
If it matters, the location of the actual program is in the "G01-Cartography" folder.
Private Sub GameMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadMap("Map_Cygnus.txt")
End Sub
Private Sub LoadMap(FileLoc As String)
FileLoc = "C:\Users\Adam\Documents\Visual Studio 2013\Projects\G01-Cartography\Maps\" + FileLoc
MsgBox("A")
Using File As New StreamReader(FileLoc)
MsgBox("B")
Dim WholeMap = File.ReadLine()
MsgBox("C")
End Using
MsgBox("D")
End Sub
What does running this show you in the debugger? Can you open the Map_Cygnus.txt file in Notepad? Set a breakpoint on the first line and run the program to see what is going on.
Private BaseDirectory As String = "C:\Users\Adam\Documents\Visual Studio 2013\Projects\G01-Cartography\Maps\"
Private Sub GameMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim WholeMap = File.ReadAllText(Path.Combine(BaseDirectory, "Map_Cygnus.txt"))
Debug.Print("Size Of Map: {0}", WholeMap.Length)
End Sub
It looks like you're using the correct methods/objects according to MSDN.
Your code runs for me in an new VB console app(.net 4.5)
A different approach then MSGBOXs would be to use Debug.WriteLine or Console.WriteLine.
If MSGBOX A shows but not B, then the problem is in constructing the stream reader.
Probably you are watching the application for output but the debugger(visual studio) has stopped the application on that line, with an exception. eg File not found, No Permission, using a http uri...
If MSGBOX C doesn't show then problem is probably that the file has problems being read.
Permissions?
Does it have a Line of Text?
Is the folder 'online'
If MSGBOX D shows, but nothing happens then you are doing nothing with WholeMap
See what is displayed if you rewite MsgBox("C") to Debug.WriteLine("Read " + WholeMap)
I have a few suggestions. Firstly, use Option Strict On, it will help you to avoid headaches down the road.
The code to open the file is correct. In addition to avoiding using MsgBox() to debug and instead setting breakpoints or using Debug.WriteLine(), wrap the subroutine in a Try...Catch exception.
Private Sub GameMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadMap("Map_Cygnus.txt")
End Sub
Private Sub LoadMap(FileLoc As String)
Try
FileLoc = "C:\Users\Adam\Documents\Visual Studio 2013\Projects\G01-Cartography\Maps\" + FileLoc
MsgBox("A")
Using File As New StreamReader(FileLoc)
MsgBox("B")
Dim WholeMap = File.ReadLine() 'dimming a variable inside a block like this means the variable only has scope while inside the block
MsgBox("C")
End Using
MsgBox("D")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Note that you normally should only catch whatever exceptions you expect, but I generally catch everything while debugging things like this.
I would also like to point out that you are only reading one line out of the file into the variable WholeMap. That variable loses scope as soon as the End Using line is hit, thereby losing the line you just read from the file. I'm assuming that you have the code in this way because it seems to be giving you trouble reading from it, but thought I would point it out anyway.
Public Class GameMain
Private WholeMap As String = ""
Private Sub GameMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadMap("Map_Cygnus.txt")
End Sub
Private Sub LoadMap(FileLoc As String)
Try
FileLoc = "C:\Users\Adam\Documents\Visual Studio 2013\Projects\G01-Cartography\Maps\" + FileLoc
Using File As New StreamReader(FileLoc)
WholeMap = File.ReadLine() 'dimming the variable above will give all of your subs inside class Form1 access to the contents of it (note that I've removed the Dim command here)
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class

Why dont the Command Button excecute the form

Good day. I Created a form that worked perfectlt, after testing the Command Button a few times and entering information into the form I decided to straiten out the form and make it tidy. after saving the form i tried to click the Command butten but this time it gave me a Error 424. Object Required.
(I tried to upload pictures with no success)
When I Check the Debug it highlight the .show command.
Private Sub CommandButton1_Click()
ClaimUserForm.Show
End Sub
I also tried:
Private Sub CommandButton1_Click()
Dim Claim as ClaimUserForm
Set Claim = new ClaimUser
claim.show
End Sub
But the debug re-appear.
in the form property window the form name is ClaimUserForm
Please help, I cant understand why it suddenly gave this problem.
Thanks
Is your button working properly? It seems it's missing the sender-object and the events.
Also set is not necessary.
Private Sub CommandButton1_Click(sender As Object, e As EventArgs) Handles CommandButton1.Click
Dim Claim As ClaimUserForm = New ClaimUser
Claim.Show
End Sub
sender As Object, e As EventArgs and Handles Button1.Click are missing.

Trouble saving ALL listbox data

Ok, so i'm trying to make an Injector. To load the DLLs, I used a File Dialog to select the DLL then write the info to a List Box. Now I want to save the data in the list box and reload the past data on the Form Load, but every method I have tried only saves the name of the DLL not the other info such as Location.
I would like to have no external files IF possible. Any solutions?
Cheers.
Edit: Source code for Open File Dialog
Private Sub OpenFileDialog1_FileOk(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim FileName As String = OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\"))
Dim DLLfileName As String = FileName.Replace("\", "")
ListBox1.Items.Add(DLLfileName)
dlls.Add(DLLfileName, OpenFileDialog1.FileName)
End Sub

VB.NET 2008 - Input to data to website controls and download results

this is my first Q on this website so let me know if I have missed any important details, and thanks in advance.
I have been asked to access a website and download the results from a user-inputted form. The website asks for a username/password and once accepted, several questions which are used to generate several answers.
Since I am unfamiliar with this area I have set up a simple windows form to tinker around with websites and try to pick things up. I have used a webbrowser control and a button to use it to view the website in question.
When I try to view the website through the control, I just get script errors and nothing loads up. I am guessing I am missing certain plug-ins on my form that IE can handle without errors. Is there anyway I can identify what these are and figure out what to do next? I am stumped.
The script errors are:
"Expected identifier, string or number" and
"The value of the property 'setsection' is null or undefined"
Both ask if I want to continue running scripts on the page. But it works in IE and I cannot see why my control is so different. It actually request a username and password which works fine, it is the next step that errors.
I can provide screenies or an extract from the website source html if needed.
Thanks,
Fwiw my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Thanks for Noseratio I have managed to get somewhere with this.
Even though the errors I was getting seemed to be related to some XML/Java/Whatever functionality going askew it was actually because my webbrowser control was using ie 7.0
I forced it into using ie 9 and all is now well. So, using my above example I basically did something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
BrowserUpdate()
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Sub BrowserUpdate()
Try
Dim IEVAlue As String = 9000 ' can be: 9999 , 9000, 8888, 8000, 7000
Dim targetApplication As String = Process.GetCurrentProcess.ToString & ".exe"
Dim localMachine As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim parentKeyLocation As String = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"
Dim keyName As String = "FEATURE_BROWSER_EMULATION"
Dim subKey As Microsoft.Win32.RegistryKey = localMachine.CreateSubKey(parentKeyLocation & "\" & keyName)
subKey.SetValue(targetApplication, IEVAlue, Microsoft.Win32.RegistryValueKind.DWord)
Catch ex As Exception
'Blah blah here
End Try
End Sub