|
Joannou H. Fegarido wrote: I do not know how to fix it. There's usually multiple ways; we will have to find one.
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
Dim name As String
Dim number As String
If i < TblContactsDataGridView.Rows.Count - 1 Then Where is i declared? Why is it not reset?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks, I think that was the problem. But i do not know how to fix it, please help me to fix. Any help would be appreciated.
|
|
|
|
|
Try something like below; there'll probably be a field with the same name - that needs to be removed.
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
Dim name As String
Dim number As String
Dim i As Integer = 0
If i < TblContactsDataGridView.Rows.Count - 1 Then
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you so much for your great help sir. I really appreciate it. I already fixed the problem, the only problem is the i because it doesn't reset to 0 once it done to navigate in datagrid. So in else statement i put i=0 and timer3.stop.
looks like this.
Timer3.Stop()
i = 0
frmStatus.ShowDialog()
Wonderful... 
|
|
|
|
|
You're welcome 
|
|
|
|
|
Hello,
I am very new to Visual Basic. I have VB 2010 Express and creating my first project, which is a small application that allows a user to create a profile.
One part is where the user can upload a Profile picture.
I can upload a specific picture to the Resources folder and can display it in a picture box by using the following:
PictureBox1.Image = My.Resources.ImageName
That works fine. However, what I want to do is allow the user to click on an "Upload" button, search for any image and have that image load in PictureBox1. I have no clue what code to use or how to write such a code.
Any help would be greatly appreciated.
Thank you.
|
|
|
|
|
|
Hi Richard,
Thank you for your reply.
I am clueless to what you mean. Sorry. Can you give an example of what way that would be done?
I am just learning so any help is appreciated.
Thank you.
|
|
|
|
|
You need to follow that link and read the documentation. You could also try searching the articles section for samples.
Veni, vidi, abiit domum
|
|
|
|
|
You cannot upload a file to the Resources folder. L:ook in the bin\Debug or bin\Release folder in your project in Windows Explorer, NOT in Solution Explorer. Notice there is no Resource folder in there.
Resources are files that are compiled into your resulting executable. You cannot add items to Resources are run-time.
You'll have to change this functionality to put user-uploaded files into a folder your application controls, like CommonApplicationData, and keep track of that filepath in your profile data structure.
|
|
|
|
|
Hi folks,
Thanks so much for the help so far.
I have tried the following, from what I can understand, but it says that
"Await is not Declared. It may be inaccessable due to its protection level"
and:
"CopyToAsync is not a member of System.IO.FileStream"
The code I have tried is:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim StartDirectory As String = "Resource\Start"
Dim EndDirectory As String = "Resource\end"
For Each filename As String In Directory.EnumerateFiles(StartDirectory)
Using SourceStream As FileStream = File.Open(filename, FileMode.Open)
Using DestinationStream As FileStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf("Resource")))
Await(SourceStream.CopyToAsync(DestinationStream))
End Using
End Using
Next
End Sub
Thanks in advance for any guidance. As I said, I am totally new.
|
|
|
|
|
Uhhh... Await?? You're a beginner. Don't start trampling through multi-threading code. You're not there yet.
Also, unless you're using VS2012 or 2013 and your project is targeting the .NET Framework 4.0 or above, you don't have access to Await. Even with .NET 4.0, I think you needed to add the "Async Targeting Pack" to your project to get at it.
Now, again, you have a problem. The directory structure you see in Solution Explorer does NOT exist on disk in your compiled application! The Resources folder does NOT exist as far as your code is concerned. You cannot enumerate the files in it because it's a concept that only exists inside Visual Studio and only up to compile-time. Once your project is compiled, the Resources folder essentially does not exist.
|
|
|
|
|
Hi David,
Thank you.
Yes, I created a new folder inside Bin/Debug called Resource, which is the one being used now.
I have no clue about what code to use as I said at the start, which is why I posted here, hoping to get some guidance.
Thanks.
|
|
|
|
|
Hi guys,
The following seems to work a bit.
If (Not System.IO.Directory.Exists("Resource")) Then
System.IO.Directory.CreateDirectory("Resource")
End If
Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
Dim FName() As String = OpenFileDialog1.FileName.Split("\\")
System.IO.File.Copy(OpenFileDialog1.FileName, "Resource\\" + FName(FName.Length - 1))
PictureBox1.Image = Image.FromFile(.FileName)
Profile.PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
It saves the image to the /bin/debug/Resource folder and displays it in the PictureBoxs as shown in the code. But when I close the program and open it again the images are no longer displayed.
Any ideas?
Thank you.
|
|
|
|
|
There isn't enough code here to definitively say what's wrong. But, one problem I see is that you're using relative path names. You're ASSUMING that the "current directory" is always the same. That's just not true, especially when using the Open/SaveFile dialogs. They change the "current directory" as you navigate through them.
ALWAYS, ALWAYS, ALWAYS, build and use absolute paths using well-known roots, such as:
Dim appPath As String = Application.StartupPath
Dim resourcesFolderPath As String = Path.Combine(appPath, "Resources")
Dim imageFilePath As String = Path.Combine(resourcesFolderPath, someUserPickedFilename)
Also, use Path.Combine to build paths. What you're doing, first, contains double backslash characters, which don't apply in VB.NET, only in C/C++/C#. Using Path.Combine, you don't worry about the backslashes at all.
You don't have to slpit a filepath from an OpenFileDialog. It'll return the full path to the selected file. From there, you use the Path class and its methods to get the filename. You don't need to split the string on, again, double backslashes which don't work in VB.NET. In VB.NET, it's a single backslash.
Dim filename As String = Path.GetFileName(userSelectedPath)
|
|
|
|
|
Hi Dan,
I have read through your correspondence with the others and I do not disagree at all with what they have been telling you. However, I would like to propose an alternative method based on what you have said.
You want to allow the user to select image to display on your form and you also want this selection to persisted between program executions (i.e. a user setting). VB.Net provides you an easy mechanism to persist variables using the My.Settings feature. You can access and define these settings by double clicking "My Project" in the Solution Explorer window and then clicking on the Settings tab.
The only issue is that the VS designer will not allow you to select "System.Drawing.Image" as the setting Type. Don't worry about that, it is only a limitation in the code generation capability of the designer and not that you can not store an image. The big requirement is that that type that you wish to store provides a mechanism to serialize the class instance. If you look at the documentation for the Image Class[^], you will see that is defined:
'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<TypeConverterAttribute(GetType(ImageConverter))> _
Public MustInherit Class Image _
Inherits MarshalByRefObject _
Implements ISerializable, ICloneable, IDisposable That <SerializableAttribute> is key to making this work. You will just have to provide the code to add the setting yourself. VB.Net handles these settings as Properties of the MySettings Class in the My namespace. Add a new Class file to your project and replace the autogenerated code with the following snippet.
Namespace My
Partial Friend NotInheritable Class MySettings
' The trick here is to tell it serialize as binary
<Global.System.Configuration.SettingsSerializeAs(Configuration.SettingsSerializeAs.Binary)> _
<Global.System.Configuration.UserScopedSettingAttribute()> _
Public Property StoredImage() As System.Drawing.Image
Get
' the String in: Me("StoredImage") must be the name of the setting
Return DirectCast(Me("StoredImage"), System.Drawing.Image)
End Get
Set(ByVal value As System.Drawing.Image)
' the String in: Me("StoredImage") must be the name of the setting
Me("StoredImage") = value
End Set
End Property
''' <summary>Dictionary of Images keyed on username</summary>
<Global.System.Configuration.SettingsSerializeAs(Configuration.SettingsSerializeAs.Binary)> _
<Global.System.Configuration.UserScopedSettingAttribute()> _
Public Property UserImages() As Dictionary(Of String, System.Drawing.Image)
Get
' the String in: Me("UserImages") must be the name of the setting
If Me("UserImages") Is Nothing Then
Me("UserImages") = New Dictionary(Of String, System.Drawing.Image)
End If
Return DirectCast(Me("UserImages"), Dictionary(Of String, System.Drawing.Image))
End Get
Set(ByVal value As Dictionary(Of String, System.Drawing.Image))
' the String in: Me("UserImages") must be the name of the setting
Me("UserImages") = value
End Set
End Property
End Class
End Namespace I have defined two Properties (StoredImage and UserImages) because I was not completely clear if your application needed to store a single image or an image for each user of the application under the same installed account. The Dictionary property gives you the ability to store multiple images keyed to a String value.
Here is a sample usage based on a Form with two Buttons and two PictureBoxes. I think you can figure this code out, but feel free to ask questions.
************** Edit: The example usage code I thought that I included.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim imgdialog As New System.Windows.Forms.OpenFileDialog()
imgdialog.Filter = "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg|All Files (*.*)|*.*"
If imgdialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim img As Image = Image.FromFile(imgdialog.FileName)
My.Settings.StoredImage = img
If My.Settings.UserImages.ContainsKey("username") Then
My.Settings.UserImages("username") = img
Else
My.Settings.UserImages.Add("username", img)
End If
My.Settings.Save()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.Image = My.Settings.StoredImage
If My.Settings.UserImages.ContainsKey("username") Then
PictureBox2.Image = My.Settings.UserImages("username")
End If
End Sub
End Class ************* End Edit
Some reference material:
To find where the config file is stored see the response from Johan Stenberg[^]
My.Settings Object[^]
modified 5-Feb-14 16:50pm.
|
|
|
|
|
Hi TnTinMn,
Thank you so much for that explanation and detailed rundown. It is beginning to make sense now.
I placed that code into Class.VB though and get the following:
Any advice on that would be so appreciated.
Thanks again,
Dan
|
|
|
|
|
Hmm, you must of copied the code by hand and named both properties StoredImage.
The second property in the example is name UserImages (the Dictionary).
|
|
|
|
|
I just edited my post and included the sample usage code that I thought I put in there last night.
To verify that this code should work, I copied and pasted from my post into VS2010 Express and it all ran fine.
Like I said above, maybe you made a typo in your attempt.
|
|
|
|
|
A docking pane is set to AutoHidePortion and permitted docking is DockLeft with AllowEndUserDocking = False
The design width of the form is 200px and the initialisation command is .Show(dockPanel, DockState.DockLeftAutoHide)
Despite the fact that AutoHidePortion is > 1 the pane is showing at around 315px = 1/4 the form width.
I have just moved from DPS ver 2.5 to ver 2.8 and in ver 2.5 this behaviour is not apparent and the form (pane) displays at the required size. I an using VB 2010.
Does anyone have any further information on this, workarounds or fixes?
I can't seem to find anything specific on the web, or in Code Project.
Thanks.
modified 31-Jan-14 11:09am.
|
|
|
|
|
TheComputerMan wrote: I can't seem to find anything specific on the web, or in Code Project. That's probably because it is not part of the .NET Framework.
Are you referring to this[^] suite? If yes, then your question should go here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It is implemented in Visual Basic therefore the question is legitimate. I will ask in the suggested forum however although I have already searched that and found nothing specific.
|
|
|
|
|
TheComputerMan wrote: It is implemented in Visual Basic therefore the question is legitimate. I never said it wasn't.
TheComputerMan wrote: I will ask in the suggested forum however although I have already searched that and found nothing specific. I doubt that there'll be specific information readily available. The reason I pointed there is because a support forum dedicated to that suite will probably have more expertise than a general .NET forum.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's OK I understand what you were saying, but I was thinking that maybe people ding the job had come across the problem and fixed it or got a workaround.
Unfortunately there is nothing much about it on that site. The problem gets a mention. Apparently it appeared in 2.6 and has not been fixed satisfactorily as far as I can tell. The forum is a bit 'thin' to say the least.
In the end, because the code has to address .NET 4.0 I simply re-compiled version 2.5 to target the .NET 4.0 framework. Since the problem does not exist in 2.5 I am happy and I am not concerned about the additions in later versions that i will not have by using 2.5.
At least if someone else experiences the problem our discussion is here to give them a pointer. Thanks for your input. 
|
|
|
|
|
TheComputerMan wrote: I simply re-compiled version 2.5 to target the .NET 4.0 framework. Since the problem does not exist in 2.5 I am happy Whehe, nice pragmatic approach
Well done 
|
|
|
|