From the past to the future, from Visual and Basic to NET. (12 techniques from VB to VB.NET) (2)

zhaozj2021-02-17  87

From the past to the future, from Visual and Basic to NET (2)

5. Read the registry. The registration form in Windows is so important, like a huge treasure forever and makes you carefully. Sometimes we must take or put some information in the registry. However, the VB provides the value of HKEY_CURRENT_USER / SOFTWARE / VB and VBA Program Settings / AppName / Section / Key. As for you need to call other API functions, I know that most people are through themselves. Modules and classes to solve this problem.

Past VB

============================================================================================================================================================================================================= ====

You can get help and code in the following URL.

Http://www.planet-source-code.com/vb/scripts/showcode.asp?lngwid=1&txtCodeId=1881

Now VB.NET

============================================================================================================================================================================================================= ====

Private sub btnwriteregistry_click (Byval Sender AS _

System.Object, ByVal e as system.eventargs

Handles btnwriteregistry.click

Dim akey as registryKey

Akey = registry.currentuser.createSubkey_

("Software / VBDotNetDemo")

Akey.setValue ("VBDotNetDemo", "VB.Net")

Messagebox.show ("The Value of the New Key"

& "'HKEY_CURRENT_USER / SOFTWARE /" & _

"VBDotNetDemo 'is:" _

& akey.getvalue ("vbdotnetdemo", _

"Default Value", _

Key created successfully ")

End Sub

6. Quickly present your array data to a listbox, if you have an ADO recordset in your hand, you can bind to a perceptual control with data binding, these controls like DATAST, for example: DataList , DataGrid, DattaretPeater. ADO has just come out that there have been many data controls that support RDO before they are not compatible.

Past VB

============================================================================================================================================================================================================= ==== Private Sub cmdpopulatelist_click ()

Dim ListItems (4) AS STRING

DIM I as integer

ListItems (0) = "one"

ListItems (1) = "Two"

ListItems (2) = "Three"

ListItems (3) = "four"

ListItems (4) = "Five"

List1.clear

For i = 0 TO 4

List1.additem ListItems (i)

NEXT

End Sub

Now VB.NET

============================================================================================================================================================================================================= ====

Private sub btnpopulatelist_click (Byval Sender AS _

System.Object, ByVal e as system.eventargs_

Handles btnpopulatelist.click

Dim ListItems () as string = {"one", "two", _

"Three", "FOUR", "FIVE"}

Listbox1.datasource = ListItems

End Sub

We should be unfamiliar with Datasource, VS. It has become a common attribute in the NET, which is just known as the data binding specifically used in VB6. More controls in ASP supports the DataSource property and will not be required to be a database connection or SELECT obtained. This data source can be any form of database source.

7. Generate a random number. How to generate a random number and make it only change in a certain range. This is a very common stuff, although we no longer write some bad simple games, but still remember to achieve an excitement and excitement that generates a random number when you have just exposed to your computer.

Past VB

============================================================================================================================================================================================================= ==== Private function getrandomnumber _

(Low as long, high as long) As long

Randomize (now ())

Getrandomnumber = CINT ((High - Low 1) * _

RND LOW)

END FUNCTION

Now VB.NET

============================================================================================================================================================================================================= ====

Private function getrandomnumber_

(Byval Low, Byval High) AS INTEGER

Getrandomnumber = new system.random (). _

Next (low, high)

END FUNCTION

8. VB6 is almost COM's best partner, and COM features in all VB6 new features can be amazed. Although COM is a binary code, some people always think that COM is life. What is GUID? However, the implementation of VB.NET is too simple, it will give people an illusion: DOTNET is a more Com technology.

Past VB

============================================================================================================================================================================================================= ====

Private Declare Function CocreateGuid LIB_

"ole32.dll" (buffer as Byte) As long

Private declare function stringFromGuid2 lib_

"ole32.dll" (Buffer as Byte, Byval LPSZ As Long, _

BYVAL CBMAX AS Long) As long

Private function getGUID () AS STRING

DIM BUFFER (15) as Byte

DIM S As String

DIM RET As Long

s = string $ (128, 0)

Ret = CocreateGuid (Buffer)

RET = StringFromGuid2 (Buffer (0), StrPtr (s), 128) getGuid = Left $ (S, RET - 1)

END FUNCTION

Now VB.NET

============================================================================================================================================================================================================= ====

Private function getGUID () AS STRING

GetGuid = "{" & _

System.guid.newguid (). Tostring & "}"

END FUNCTION

9. Add a value of a variable. I used to envy C or Java i ; i; k = 2 This simple grammar, now VB.NET also supports such grammar, although some violates VB simple purpose, but more people like it This code is also written in VB.

Past VB

============================================================================================================================================================================================================= ====

MyValue = MyValue 10

Now VB.NET

============================================================================================================================================================================================================= ====

MyValue = 10

The same is:

MyValue - = 10

MyValue / = 10

MyValue * = 10

转载请注明原文地址:https://www.9cbs.com/read-31051.html

New Post(0)