vb.net Image and BorderStyle is not a member of 'WindowsApplication.PictureBox' - vb.net

I met the following errors in my vb.net project:
(1) Image is not a member of 'WindowsApplication.PictureBox'
(2) BorderStyle is not a member of 'WindowsApplication.PictureBox'
The following is my code:
Dim NewPicBox As New PictureBox
NewPicBox.Visible = True
NewPicBox.Width = 1200
NewPicBox.Height = 1200
NewPicBox.Top = 0
NewPicBox.Left = 0
NewPicBox.BorderStyle = BorderStyle.FixedSingle
NewPicBox.Image = Image.FromFile("D:\11.gif")
Me.Controls.Add(NewPicBox)
I have already imports system.drawing in it. Tried to searching from internet, even cannot find the similar issue. I am using .net Framework 3.5.
Can anybody help me? thanks.

The fact that the error messages says WindowsApplication.PictureBox means that you have defined a type or namespace in your project named PictureBox and the compiler is inetrpreting your code as referring to that rather than the System.Windows.Forms.PictureBox class. You should generally avoid such name clashes if possible but, if you must use the same name as an existing type, you must then qualify the name of that existing type when you use it in code, i.e. instead of:
Dim NewPicBox As New PictureBox
use:
Dim NewPicBox As New Windows.Forms.PictureBox
In this case though, I very much doubt that using PictureBox as the name of one of your own types is appropriate. I suggest that you change it and then the code you have will work.

Related

ZXing.NET EAN8Writer getChecksum

I want to check my (bar)code or get missing checksum number before creating a barcode picture in VB.NET. This is critical parts of minimized example on how this look like:
Imports ZXing
Imports ZXing.Common
Imports ZXing.OneD
...
Dim writer As EAN8Writer = New EAN8Writer
Dim data As String = "1234567" '(0)
Dim check As Integer = UPCEANReader.getStandardUPCEANChecksum(data)
I find that part of code in a various examples on the net. But on my system I get error 'getStandardUPCEANChecksum is not a member of UPCEANReader'. Why this don't work as expected?
Is here any other way to get checksum for such case except to calculate it manually?
The method UPCEANReader.getStandardUPCEANChecksum() is declared as "internal" and can't be accessed from outside the library (without using reflection or similar stuff).
You can copy the source code into your own application if you want to use it.

Type mismatch in set frame statement

I am trying to use the Outlook View Control in Microsoft Access. As I understand it, this can only be used by embedding it in a Microsoft Forms 2.0 Frame control.
After being unsuccessful, I downloaded a database from Experts Exchange that worked fine. When I tried to replicate it in my database I received a Type Mismatch error. I then imported the form from the database I had downloaded which was working correctly, but when I ran it in my database, I get the same type mismatch error.
Private Sub Form_Open(Cancel As Integer)
Dim MyFrame As Frame
Dim vc As viewctl
Set MyFrame = Me.Frame0.Object
Set vc = MyFrame!ViewCtl1
With vc
.Folder = "John Smith"
End With
End Sub
The code is very simple, but I fail to understand what is causing the problem. The references have been added for Microsoft Forms 2.0 object library and Microsoft Outlook View Control. In fact, I have all of the references in the working database I downloaded together with others in my database.
The code is as follows:
The error throws up on Set MyFrame = Me.Frame0.Object as
error 13 Type Mismatch.
The folder name is the name of a shared calendar.
If anyone can help I would be very grateful.
The link to the database I downloaded is:
https://www.experts-exchange.com/articles/4617/Outlook-View-Control-OVC-part-two-Changing-folders-and-interacting-programmatically-Access-2007.html#comments
Assuming you mean Frame to refer to the MSForms type, then you may need to fully-qualify it:
Dim MyFrame As MSForms.Frame
In general, it's a good habit to fully-qualify types that have a name that may exist in more than just one referenced type library: if Access.Frame exists, then it has a higher priority in the resolution order (see ordering of libraries in the tools/references dialog), so an unqualified Frame would be implicitly Access.Frame, hence the type mismatch.

VB.NET - Dynamically created controls and how to manipulate them

If I create a control like so:
Dim fb As New Label
With fb
.Name = "newLabel"
.text = "some text"
<etc.>
Me.Controls.Add(fb)
End With
Now, if I wanted to change the text on that label during run time, I would normally do:
newLabel.text = "some other text"
Unfortunately, Visual Studio won't let me do that as 'newLabel' isn't defined until run time.
So, my question is: How do I reference a control created in such a way? (The only way I can think of is to loop through all controls until I find the one I'm looking for, but that seems a tad inefficient to me.)
'newLabel' isn't defined until run time"
That isn't really accurate. You are confusing the object with a variable used to reference the object. When you add a control to a form in the designer, VS generates code to create and configure that control. It's much the same as the code you wrote and posted. You can see it in the designer code file, which you can access if you click the 'Shoe All Files' button in the Solution Explorer. That code includes a member variable to which the created object is assigned. You then use that member variable to refer to that object in code.
If you're creating controls at run time then you generally can't declare a member variable for each one to be assigned to because you don't know how many there will be. If you do know how many there will be then you probably ought to be adding them at design time. That means that you have two options:
Declare a single member variable that will refer to a collection of controls created at run time and then access then via name or index from that.
Access them by name from the Controls collection of the form or other container control that you must add them to in order for them to be displayed.
Option 2 requires that you provide a unique name for each control when you create it. Option 1 doesn't require a name at all, although it doesn't preclude one.
Option 1 might look like this:
At the class level:
Private labels As New List(Of Label)
In a method somewhere:
For i = 0 To 9
Dim lbl As New Label
labels.Add(lbl)
Controls.Add(lbl)
Next
Later:
Dim lbl = labels(recordIndex)
Option 2 might look like this:
In a method somewhere:
For i = 0 To 9
Dim lbl As New Label With {.Name = "titleLabel" & i}
Controls.Add(lbl)
Next
Later:
Dim lbl = DirectCast(Controls("titleLabel" & recordIndex), Label)

In VB.NET does MS require the fully qualified function name for the Right or Left string functions?

According to the Microsoft documentation, to determine the number of characters in str, use the Len function. If used in a Windows Form, or any other class that has a Right property, you must fully qualify the function with "Microsoft.VisualBasic.Strings.Right".
If I set "Imports Microsoft.VisualBasic" at the top of the form I still have to use the fully qualified name in my code. Why does MS require this?
Because, without the fully qualified name, if there are two methods with the same name, the compiler cannot choose one over the other. So you should take care of the problem giving the correct hint
To ease your typing you could add at the top of your code file this version of the Imports statement
Imports VB6 = Microsoft.VisualBasic
and then you could type
Dim stringLen = VB6.Len(yourStringVariable)
This is the MSDN introduction to Namespaces in VB.NET, in particular, in the first lines of the article is explained your problem Avoiding Namespaces Collisions
NET Framework namespaces address a problem sometimes called namespace
pollution, in which the developer of a class library is hampered by
the use of similar names in another library. These conflicts with
existing components are sometimes called name collisions.
For example, if you create a new class named ListBox, you can use it
inside your project without qualification. However, if you want to use
the .NET Framework ListBox class in the same project, you must use a
fully qualified reference to make the reference unique. If the
reference is not unique, Visual Basic produces an error stating that
the name is ambiguous.
And by the way, start to use the equivalent framework methods for Right, Left, and Len.
They are still available only to help the porting of old VB6 application, (and sometime they work differently). In new applications I suggest to use
string.Substring(start, len)
string.Length
A winform, Form (derived from Control), have properties named Right and Left.
Public Class Form1
Inherits Form
Public Sub Test()
Dim location_left As Integer = Me.Left
Dim location_right As Integer = Me.Right
'Or simply:
location_left = Left '<- (Referring to Me.Left, not Microsoft.VisualBasic.Strings.Left)
location_right = Right '<- (Referring to Me.Right, not Microsoft.VisualBasic.Strings.Right)
End Sub
End Class
Therefore you'll need the use the full qualify name.

VB6 keyword Set what does it mean?

I been browsing an old VB6 code and I saw something like this
Set AST = CreateObject("ADODB.Stream")
I have experience using VB6 and VB.NET but I never use this keyword Set before in my VB6 projects. I researched a lot in the internet what is the use of Set and what I only know is the usage in Properties which is only I know in VB.NET
Public Property myProperty As String
Get
Return _myProperty
End Get
Set(value as String)
_myProperty = value
End Set
End Property
and I think Set is used differently on the code above. What is the difference of the two approaches? I want to know what does the Set do in VB6
Set is assigning a new reference to the AST variable, rather than assigning a value to (the object currently referenced by AST)'s default property.
There's not much VB 6 documentation around on the web, but1 some of the help for VB.Net still references the older ways.
See Default Property Changed for Visual Basic 6 Users:
In Visual Basic 6.0, default properties are supported on objects. On a Label control, for example, Caption is the default property, and the two assignments in the following example are equivalent.
Dim lbl As Label
lbl = "Important"
lbl.Caption = "Important"
While default properties enable a certain amount of shorthand in writing Visual Basic code, they have several drawbacks:
...
Default properties make the Set statement necessary in the Visual Basic language. The following example shows how Set is needed to indicate that an object reference, rather than a default property, is to be assigned.
Dim lbl1 As Label, lbl2 As Label
lbl1 = "Saving" ' Assign a value to lbl1's Caption property.
lbl2 = lbl1 ' Replace lbl2's Caption property with lbl1's.
Set lbl2 = lbl1 ' Replace lbl2 with an object reference to lbl1.
So, in VB.Net, Let and Set became obsolete (in fact, Let was already pretty much obsolete in VB 6) because the language rules changed. An assignment A = B, if A is a reference, is always assigning a new reference to A.
1MarkJ has supplied links to the older VB6 documentation in the comments.