Skip to content

Commit 8ee2426

Browse files
committed
reinstate and move
1 parent 16c5959 commit 8ee2426

File tree

30 files changed

+860
-21
lines changed

30 files changed

+860
-21
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'<snippet1>
2+
3+
Imports System.Runtime.InteropServices
4+
5+
Module Module1
6+
7+
Sub Main()
8+
Console.WriteLine(vbcrlf + "Sample: VB System.Runtime.InteropServices.Marshal.GetActiveObject.vb" + vbcrlf)
9+
GetObj(1, "Word.Application")
10+
GetObj(2, "Excel.Application")
11+
End Sub
12+
13+
14+
Sub GetObj(ByVal i As Integer, ByVal progID As [String])
15+
Dim obj As [Object] = Nothing
16+
17+
Console.WriteLine((vbLf & i & ") Object obj = GetActiveObject(""") + progID & """)")
18+
Try
19+
obj = Marshal.GetActiveObject(progID)
20+
Catch e As Exception
21+
Write2Console((vbLf & " Failure: obj did not get initialized" & vbLf & " Exception = ") + e.ToString().Substring(0, 43), 0)
22+
End Try
23+
24+
If obj IsNot Nothing Then
25+
Write2Console(vbLf & " Success: obj = " & obj.ToString(), 1)
26+
End If
27+
End Sub
28+
29+
Sub Write2Console(ByVal s As [String], ByVal color As Integer)
30+
Console.ForegroundColor = If(color = 1, ConsoleColor.Green, ConsoleColor.Red)
31+
Console.WriteLine(s)
32+
Console.ForegroundColor = ConsoleColor.Gray
33+
End Sub
34+
35+
End Module
36+
37+
'Expected Output:
38+
'
39+
'Sample: VB System.Runtime.InteropServices.Marshal.GetActiveObject.vb
40+
'
41+
'1) Object obj = GetActiveObject("Word.Application")
42+
'
43+
' Success: obj = System.__ComObject
44+
'
45+
'2) Object obj = GetActiveObject("Excel.Application")
46+
'
47+
' Failure: obj did not get initialized
48+
' Exception = System.Runtime.InteropServices.COMException
49+
'
50+
'</snippet1>

snippets/visualbasic/System/Array/Clear/Project.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
</PropertyGroup>
77

88
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'<snippet1>
2+
Imports System.Text
3+
4+
Class Sample
5+
6+
Public Shared Sub Main()
7+
Dim s1 As String = "MyTest"
8+
Dim s2 As String = New StringBuilder().Append("My").Append("Test").ToString()
9+
Dim s3 As String = String.Intern(s2)
10+
Console.WriteLine($"s1 = {s1}")
11+
Console.WriteLine($"s2 = {s2}")
12+
Console.WriteLine($"s3 = {s3}")
13+
Console.WriteLine($"Is s2 the same reference as s1?: {s2 Is s1}")
14+
Console.WriteLine($"Is s3 the same reference as s1?: {s3 Is s1}")
15+
End Sub
16+
End Class
17+
'
18+
's1 = MyTest
19+
's2 = MyTest
20+
's3 = MyTest
21+
'Is s2 the same reference as s1?: False
22+
'Is s3 the same reference as s1?: True
23+
'
24+
'</snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'<snippet1>
2+
Class Sample
3+
Public Shared Sub Main()
4+
Dim s1 As String = "abcd"
5+
Dim s2 As String = ""
6+
Dim s3 As String = Nothing
7+
8+
Console.WriteLine("String s1 {0}.", Test(s1))
9+
Console.WriteLine("String s2 {0}.", Test(s2))
10+
Console.WriteLine("String s3 {0}.", Test(s3))
11+
End Sub
12+
13+
Public Shared Function Test(s As String) As String
14+
If String.IsNullOrEmpty(s) Then
15+
Return "is null or empty"
16+
Else
17+
Return String.Format("(""{0}"") is neither null nor empty", s)
18+
End If
19+
End Function
20+
End Class
21+
' The example displays the following output:
22+
' String s1 ("abcd") is neither null nor empty.
23+
' String s2 is null or empty.
24+
' String s3 is null or empty.
25+
' </snippet1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'<snippet1>
2+
Public Class ToLowerTest
3+
4+
Public Shared Sub Main()
5+
Dim info As String() = {"Name", "Title", "Age", "Location", "Gender"}
6+
7+
Console.WriteLine("The initial values in the array are:")
8+
9+
Dim s As String
10+
For Each s In info
11+
Console.WriteLine(s)
12+
Next
13+
14+
Console.WriteLine("{0}The lowercase of these values is:", Environment.NewLine)
15+
16+
For Each s In info
17+
Console.WriteLine(s.ToLower())
18+
Next
19+
20+
Console.WriteLine("{0}The uppercase of these values is:", Environment.NewLine)
21+
22+
For Each s In info
23+
Console.WriteLine(s.ToUpper())
24+
Next
25+
End Sub
26+
End Class
27+
' The example displays the following output:
28+
' The initial values in the array are:
29+
' Name
30+
' Title
31+
' Age
32+
' Location
33+
' Gender
34+
'
35+
' The lowercase of these values is:
36+
' name
37+
' title
38+
' age
39+
' location
40+
' gender
41+
'
42+
' The uppercase of these values is:
43+
' NAME
44+
' TITLE
45+
' AGE
46+
' LOCATION
47+
' GENDER
48+
'</snippet1>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'<snippet1>
2+
' Sample for String.ToLower(CultureInfo)
3+
Imports System.Globalization
4+
5+
Class Sample
6+
Public Shared Sub Main()
7+
Dim str1 As [String] = "INDIGO"
8+
' str2 = str1, except each 'I' is '\u0130' (Unicode LATIN CAPITAL I WITH DOT ABOVE).
9+
Dim str2 As New [String](New [Char]() {ChrW(&H0130), "N"c, "D"c, ChrW(&H0130), "G"c, "O"c})
10+
Dim str3, str4 As [String]
11+
12+
Console.WriteLine()
13+
Console.WriteLine("str1 = '{0}'", str1)
14+
15+
Console.WriteLine()
16+
Console.WriteLine("str1 is {0} to str2.", _
17+
IIf(0 = [String].CompareOrdinal(str1, str2), "equal", "not equal"))
18+
CodePoints("str1", str1)
19+
CodePoints("str2", str2)
20+
21+
Console.WriteLine()
22+
' str3 is a lower case copy of str2, using English-United States culture.
23+
Console.WriteLine("str3 = Lower case copy of str2 using English-United States culture.")
24+
str3 = str2.ToLower(New CultureInfo("en-US", False))
25+
26+
' str4 is a lower case copy of str2, using Turkish-Turkey culture.
27+
Console.WriteLine("str4 = Lower case copy of str2 using Turkish-Turkey culture.")
28+
str4 = str2.ToLower(New CultureInfo("tr-TR", False))
29+
30+
' Compare the code points in str3 and str4.
31+
Console.WriteLine()
32+
Console.WriteLine("str3 is {0} to str4.", _
33+
IIf(0 = [String].CompareOrdinal(str3, str4), "equal", "not equal"))
34+
CodePoints("str3", str3)
35+
CodePoints("str4", str4)
36+
End Sub
37+
38+
Public Shared Sub CodePoints(title As [String], s As [String])
39+
Console.Write("{0}The code points in {1} are: {0}", Environment.NewLine, title)
40+
Dim c As Char
41+
For Each c In s
42+
Console.Write("{0:x4} ", AscW(c))
43+
Next c
44+
Console.WriteLine()
45+
End Sub
46+
End Class
47+
'
48+
'str1 = 'INDIGO'
49+
'
50+
'str1 is not equal to str2.
51+
'
52+
'The code points in str1 are:
53+
'0049 004e 0044 0049 0047 004f
54+
'
55+
'The code points in str2 are:
56+
'0130 004e 0044 0130 0047 004f
57+
'
58+
'str3 = Lower case copy of str2 using English-United States culture.
59+
'str4 = Lower case copy of str2 using Turkish-Turkey culture.
60+
'
61+
'str3 is equal to str4.
62+
'
63+
'The code points in str3 are:
64+
'0069 006e 0064 0069 0067 006f
65+
'
66+
'The code points in str4 are:
67+
'0069 006e 0064 0069 0067 006f
68+
'</snippet1>

0 commit comments

Comments
 (0)