|
I'm facing a problem with VB.NET 2022 that I recently installed on my PC. I'm new to programming, so I'd appreciate some guidance on this issue.
The problem I'm encountering is related to the "Windows Form App" template in VB.NET 2022. Here's what's happening:
Initial Launch: When I launch VB.NET 2022 for the first time and create a new project using the "Windows Form App" template, everything works as expected. The form is displayed correctly.
Subsequent Launches: However, if I close VB.NET and reopen it, the "Windows Form App" template seems to be missing. It's not available in the list of project templates. This happens every time I close and reopen VB.NET.
Opening Previous Projects: Additionally, if I try to open a project that I created using the "Windows Form App" template, I encounter an error message.
I'm really eager to learn and get started with programming, so this issue is quite frustrating for me. As a beginner, I would greatly appreciate any assistance or guidance you can provide to help me resolve this problem.
Thank you so much for your time and help!
|
|
|
|
|
ionline4u wrote: if I try to open a project that I created using the "Windows Form App" template, I encounter an error message.
And what does this "error message" tell you?
|
|
|
|
|
i have seen the error message only one time and do not notice about the error.Now the designer is also disapear.I try to retrive the error message but this time the error message is also disapear.
|
|
|
|
|
Why is it every noob thinks the error message isn't important? IT'S THE ONE PIECE OF INFORMATION EVERYONE NEEDS TO TROUBLESHOOT THE PROBLEM!
I would recommend uninstalling Visual Studio and reinstalling it and see if you can get the error message again or it just works after that.
|
|
|
|
|
Because we are experienced we must have seen all error messages, and can guess which one the OP is talking about.
|
|
|
|
|
I assume that you are referring to Visual Studio 2022, as I do not think there is an application named VB.NET 2022. You should check that you have the Visual Basic workload correctly installed - use the "Extensions" -> "Manage Extensions" menu items. Also, check which template you are using: "Windows Forms App"* or "Windows Forms App (.NET Framework)". You can gather further information by examining the folders where your projects are being saved.
*The first of these use the new .NET core versions of the code and framework.
|
|
|
|
|
Generating a small printing program. I have Brother color laser printer that can duplex print. However, when I get the CanDuplex value, it returns False:
pd.PrinterSettings.CanDuplex
The interesting thing is that checking for color capability works just fine:
pd.PrinterSettings.SupportsColor
Accessing the printer via conventional MS Office applications (as well as other applications like Acrobat) has no problem identifying that the printer can print in duplex.
Thoughts?
Pound to fit, paint to match
modified 21-Aug-23 11:37am.
|
|
|
|
|
|
Please I am using VB.net 2019 and Sql 2016 and I have the below codes which inserts the pdf into the database successfully. But retrieving it becomes a problem for me and that is not the case for an image. I want to convert and retrieve this line of code into pdf "Me.Pdf1.Image=Image.fromStream(ms)" which gives an exception because it is not an image but pdf in the database. Please help me. Thank
OpenFileDialog1.ShowDialog()
txtPdfPath.Text = OpenFileDialog1.FileName
Dim ms1 As New MemoryStream
frmBPA1.Pic1.Image.Save(ms1, frmBPA1.Pic1.Image.RawFormat)
SqlQuery = "Insert into BPA1 (Pdf1)Values(@Pdf1)"
com.Parameters.AddWithValue("@Pdf1", ms1.ToArray)
com.CommandText = SqlQuery
com.CommandType = CommandType.Text
SQLCon.Open()
com.ExecuteNonQuery()
SQLCon.Close()
Dim strQuery As String = "Select df1 from BPA1"
SQLCon1.Open()
comFile = New SqlCommand(strQuery, SQLCon1)
comFile.Parameters.AddWithValue("@ReceiptNo", Me.txtReceiptNo.Text.Trim)
daFile = New SqlDataAdapter(comFile)
daFile.Fill(taFile)
If taFile.Rows(0).Item("Pic1") IsNot DBNull.Value Then
Dim img() As Byte
img = taFile.Rows(0).Item("Pdf1")
Dim ms As New MemoryStream(img)
If img.Length <> "0" Then
Me.Pic1.Image = Image.FromStream(ms)
End If
|
|
|
|
|
txtPdfPath.Text = OpenFileDialog1.FileName
That is not uploading anything, OpenFileDialog gets filenamse from the uiser, but it does not read them.
frmBPA1.Pic1.Image.Save(ms1, frmBPA1.Pic1.Image.RawFormat)
SqlQuery = "Insert into BPA1 (Pdf1)Values(@Pdf1)"
You create a memory stream object ms1 from some image data. You then try to save something that you have saved in the variable named Pdf1 , but you have not placed any data in Pdf1 that I can see. And why are you treating a PDF file as image data?
|
|
|
|
|
Thanks for the reply. Please storing the pdf is not a problem but retrieving it is issue for now. Please how do I retrieve this line Me.Pic1.Image = Image.FromStream(ms) and convert it into pdf. This line of code was used to retrieve image file correctly and I used the same process to store a pdf file but the above code to retrieve is it is the problem. Thanks
Dim strQuery As String = "Select ReceiptNo,Pic1 from BPA1 where ReceiptNo=@ReceiptNo"
SQLCon1.Open()
comFile = New SqlCommand(strQuery, SQLCon1)
comFile.Parameters.AddWithValue("@ReceiptNo", Me.txtReceiptNo.Text.Trim)
daFile = New SqlDataAdapter(comFile)
daFile.Fill(taFile)
If taFile.Rows(0).Item("Pic1") IsNot DBNull.Value Then
Dim img() As Byte
img = taFile.Rows(0).Item("Pic1")
Dim ms As New MemoryStream(img)
If img.Length <> "0" Then
Me.Pic1.Image = Image.FromStream(ms)
Else
Me.Pic1.Image = Nothing
End If
End If
|
|
|
|
|
If you cannot retrieve the PDF data then how can you be sure that you have saved it correctly? As I mentioned in my previous response, I cannot see any PDF data being saved.
|
|
|
|
|
That demonstrates a misunderstanding of what a PDF is.
To view an image such as a png you use an image viewer that supports png images. To view a PDF you use a PDF viewer. Those are two different things.
Your thought process should be - first section.
1. Find the file (it does not matter that it is a PDF.)
2. Store the bytes in the file as binary/raw in the database. At this point it is not actually a PDF (and certainly not an image), but rather just binary/raw data.
Second section
1. Load the binary data
2. Handle the binary data as a PDF file. Such as figuring out how to either use a PDF viewer or deferring to something (like browser).
From the above this means that the following code is always going to be wrong. Because it is not an image.
Image.FromStream(ms)
|
|
|
|
|
How to access scanner device in vb?
|
|
|
|
|
This question can only be answered with the documentation of this device and perhaps additional information from the distributer.
|
|
|
|
|
|
<pre>Hi, i am quit new to .net. But this should be easy for you guys
the output of a string is 202205W24 or 202205W1
I want the last digit so 24 or 1 from the string and use those digits as a string</pre>
|
|
|
|
|
|
|
Was the extra 'c' a test for the observant?
|
|
|
|
|
|
|
I've been struggling to send this CURL request in VB.NET and hope someone can help..
Here is a link to the documentation of the exact request I'm trying to send.
This is the sample CURL request:
curl -u 'username:token' 'https://api.dev.name.com/v4/domains' -X POST -H 'Content-Type: application/json' --data '{"domain":{"domainName":"example.org"},"purchasePrice":12.99}'
Here is the code that I put together and tested:
Dim uri As New Uri("https://api.dev.name.com/v4/domains")
Dim myUsername As String = txtUsername.Text.Trim & ":" & txtApiKey.Text.Trim
Dim data As String = "{""domain"":{""domainName"":""example.org""},""purchasePrice"":12.99}"
Dim dataByte As Byte()
request = WebRequest.Create(uri)
request.Headers.Add(HttpRequestHeader.Authorization, "Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes(myUsername)))
request.ContentType = "application/json"
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
request.Method = "POST"
dataByte = Encoding.UTF8.GetBytes(data)
request.GetRequestStream.Write(dataByte, 0, dataByte.Length)
Dim myResp As HttpWebResponse
myResp = request.GetResponse()
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
WebResponse = myreader.ReadToEnd()
MsgBox(WebResponse)
However, the code above always returns a (400) Bad Request.
Here is another variation of pretty much the same code which I tried:
Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse
Dim myUsername As String = "username:token"
myReq = HttpWebRequest.Create("https://api.dev.name.com/v4/domains")
myReq.Method = "POST"
myReq.ContentType = "application/json"
myReq.Headers.Add("Authorization", "Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes(myUsername)))
Dim myData As String = "{""domain"":{""domainName"":""example.org""},""purchasePrice"":12.99}"
Dim dataBytes As Byte() = Encoding.UTF8.GetBytes(myData)
myReq.GetRequestStream.Write(dataBytes, 0, dataBytes.Length)
myResp = myReq.GetResponse()
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
WebResponse = myreader.ReadToEnd()
MsgBox(WebResponse)
But, as you can already guess, it also returns a 400 (Bad Request).
|
|
|
|
|
In your CURL command, you are using the '-u' option to provide the username and token as a basic authentication header. In your VB.NET code, you're attempting to encode the credentials manually. Make sure that 'myUsername' has the correct username and token values, and try using the Credentials property of the 'WebRequest' object instead of manually adding the header -
request.Credentials = New NetworkCredential(txtUsername.Text.Trim, txtApiKey.Text.Trim)
The JSON data you're sending in the CURL command needs to be properly serialized before sending it, we use Newtonsoft.Json, not sure if it will help in your situation, if so you can use it where you create an anonymous type to represent the JSON structure and then serializes it using 'JsonConvert.SerializeObject()' -
Imports Newtonsoft.Json
Dim domainData As New With {
.domain = New With {
.domainName = "example.org"
},
.purchasePrice = 12.99
}
Dim data As String = JsonConvert.SerializeObject(domainData)
You need to close the request stream before sending the request -
request.GetRequestStream.Close()
Instead of directly displaying returned responses in a message box, you can return the status codes and any error messages further by using -
Dim statusCode As Integer = CType(myResp, HttpWebResponse).StatusCode
Dim responseText As String = String.Empty
If statusCode = HttpStatusCode.OK Then
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
responseText = myreader.ReadToEnd()
End If
MsgBox(responseText)
I hope any of these suggestions help.
|
|
|
|
|
Hey Andre,
Thanks so much for your detailed reply and explanation! I imported Newtonsoft.json no problem and tried implementing your changes. On a positive note, I'm no longer getting a (400) Bad Request reply. However, I'm now getting a (401) Unauthorized response. I've double checked my login details and made sure they were correct. I also tried testing in both the OTE (operational test environment) and the LIVE environment because the details are slightly different for each, but received the same error on both.
Could this be due to how the credentials are now being passed?
Also, if I close "GetRequestStream" before sending the request then I get a message the connection was suddenly terminated when trying to send the request. However, if I put it directly after writing to the stream that issue goes away. Here is a look at my updated code:
Dim uri As New Uri("https://api.dev.name.com/v4/domains")
Dim domainData As New With {
.domain = New With {
.domainName = "example.org"
},
.purchasePrice = 12.99
}
Dim data As String = JsonConvert.SerializeObject(domainData)
Dim dataByte As Byte()
request = WebRequest.Create(uri)
request.Credentials = New NetworkCredential(txtUsername.Text.Trim, txtApiKey.Text.Trim)
request.ContentType = "application/json"
request.Method = "POST"
dataByte = Encoding.UTF8.GetBytes(data)
request.GetRequestStream.Write(dataByte, 0, dataByte.Length)
request.GetRequestStream.Close()
Dim myResp As HttpWebResponse
myResp = request.GetResponse()
Dim statusCode As Integer = CType(myResp, HttpWebResponse).StatusCode
Dim responseText As String = String.Empty
If statusCode = HttpStatusCode.OK Then
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
responseText = myreader.ReadToEnd()
End If
MsgBox(responseText)
Any suggestions? Thanks again!
|
|
|
|