£ symbol not beind Read from TXT file in Visual Basic 2010 - vb.net

When i run my program to open a txt file, it doesnt display the £ symbol. Is there a way to display it? Heres my code
Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main()
Dim path As String = ("H:\16.1\Stock.txt")
' Open the file to read from.
Dim readText() As String = File.ReadAllLines(path, Encoding.UTF8)
Dim Z As String
For Each Z In readText
Console.WriteLine(Z)
Next
Console.ReadLine()
End Sub
End Class

Related

How would I fix this issue; Imports System.Security.Cryptography will not function with Imports System.Net

I am making a program in VB.Net which requires the imports of four import thingamajiggys. However, Imports System.Security.Cryptography will not work alongside each other imports.
I've tried arranging the order they work in. Imports System.Security.Cryptography will not work at all with Systems.Net, but it will work alongside Imports System.Text and Imports System.IO
Imports System.Security.Cryptography
Imports System.IO
Imports System.Net
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Function SHA1(ByVal Content As String) As String
Dim Molecule As New Security.Cryptography.SHA1CryptoServiceProvider
Dim bytestring() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
bytestring = Molecule.ComputeHash(bytestring)
Dim finalstring As String = Nothing
For Each bt As Byte In bytestring
finalstring &= bt.ToString("x2")
Next
Return finalstring
End Function
A red wiggled line (like the spelling mistake in Word) appears under Security.Cryptography.SHA1CryptoServiceProvider but only when Systems.Net has been imported. Why does this happen?
You are getting the red wiggly line because System.Net also has a 'Security' namespace and it's trying to find Cryptography.SHA1CryptoServiceProvider in there.
To fix it either type
Dim Molecule As New System.Security.Cryptography.SHA1CryptoServiceProvider
or
Dim Molecule As New SHA1CryptoServiceProvider
You can use aliases.
Imports CryptoSecurity = System.Security
Imports MyNet = System.Net
Then in code
Dim Molecule As New CryptoSecurity.Cryptography.SHA1CryptoServiceProvider
You can use any names that make sense to you for the alias.

'imports' statement must precede any declarations

module module1
imports System.Collections.Generic
imports System.Io
sub main()
dim subject as string
dim topic(5) as string
dim question(5) as string
dim foundfile as List
dim directory as string
console.writeline("enter the subject your revising")
subject=console.readline()
directory="C:\Users\Zak\Documents\revisionhog\subjects\physics\imaging"
For each file as String In IO.directory.Getfiles(directory, "*.pdf", IO.SearchOption.AllDirectories)
foundfile.add(file)
Next
for x = 0 to 5
console.writeline(foundFile)
next
end sub
end module
tyring to add file that i have found after a search to a list of strings.
i thought that i had placed import before declarations???
help???
imports System.Collections.Generic
imports System.Io
module module1
sub main()
dim subject as string
dim topic(5) as string
dim question(5) as string
dim foundfile as List
dim directory as string
console.writeline("enter the subject your revising")
subject=console.readline()
directory="C:\Users\Zak\Documents\revisionhog\subjects\physics\imaging"
For each file as String In IO.directory.Getfiles(directory, "*.pdf", IO.SearchOption.AllDirectories)
foundfile.add(file)
Next
for x = 0 to 5
console.writeline(foundFile)
next
end sub
end module
The imports come first, like you mentioned. This fixes the problem with the import statements, but your question is a bit unclear. If you have other issues, please state those clearly.

Why the XUnit attributs aren't recognised?

I installed the libraries xUnit with NuGet, and added references but I have errors because of the attributes [Theory], [InlineData("11/12/2011","2011-11-12")] and [Fact].
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports System.Text.RegularExpressions
Imports FluentAssertions
Imports Xunit
Imports System
Imports System.Diagnostics
Imports Xunit.Extensions
Public Class XUnitClassTest
[Theory]
[InlineData("11/12/2011","2011-11-12")]
Public Sub test(input As String, output As String)
Dim pattern As String = "\d+|[A-Za-zÀàÂâÄäÇçÉéÈèÊêËëÎîÏïÔôÖöÙùÛûÜü']+"
Dim matchList As MatchCollection = Regex.Matches(input, pattern)
Dim matchArray(matchList.Count - 1) As Match
matchList.CopyTo(matchArray, 0)
Dim manager As Processeur = New Processeur
manager.GetData(matchArray.Select(Function(a) a.ToString())).Should().Be(output)
End Sub
[Fact]
Public Sub FactMethodName()
Write(DateTime.Parse("1658").ToString())
End Sub
Public Shared Sub Write(format As String, ParamArray param As Object())
Console.WriteLine(format, param)
End Sub
End Class
You are using C# attribute syntax in VB.NET.
VB.NET syntax would be
<Fact>
Public Sub FactMethodName()
Write(DateTime.Parse("1658").ToString())
End Sub
and so on.

SSIS script task component to write Input0Buffer to a text file

I'm trying to dump all input0Buffer to a txt file, to end my struggle with making the flat destination re-usable as i've over 100 package and each structure and columns are different.
I'm redirecting the error rows to a flat file, so it's a nightmare to set that manually in every package, so I wanna write the whole input without specifieng Row.Name, all of them into text file.
I'm up to the point that i'm getting only one column!! it's driving me crazy!!
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.IO
Imports System.Reflection
Imports System.Xml
Imports Microsoft.SqlServer.Dts.Pipeline
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute()> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
Dim textWriter As StreamWriter
Private inputBuffer As PipelineBuffer
Public Overrides Sub ProcessInput(ByVal InputID As Integer, ByVal Buffer As Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer)
inputBuffer = Buffer
MyBase.ProcessInput(InputID, Buffer)
End Sub
Public Overrides Sub PreExecute()
MyBase.PreExecute()
textWriter = New StreamWriter( "c:\Test4.txt", True)
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
textWriter.Close()
''
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim delim As String = ", "
Dim RowCount As Integer = 0
For RowCount = 0 To inputBuffer.ColumnCount = -1
If inputBuffer.Item(RowCount).ToString() = "" Then
inputBuffer.Item(RowCount) = String.Empty
End If
Next
textWriter.WriteLine(inputBuffer.Item(RowCount).ToString() & delim)
End Sub
End Class
can anyone help me please?
The issue is where your write is at. You are writing outside of your For loop. You loop through each row and set the value of the entry to String.Empty but you aren't doing any writing to the textWriter here. Adjust the code as follows:
Dim myBuilder As New StringBuilder
For RowCount = 0 To inputBuffer.ColumnCount = -1
If inputBuffer.Item(RowCount).ToString() = "" Then
inputBuffer.Item(RowCount) = String.Empty
End If
myBuilder.Append(inputBuffer.Item(RowCount).ToString() & delim)
Next
textWriter.WriteLine(myBuilder.ToString)
That will ensure that each column gets written. The only issue will be that your last column will have a delimiter after it. You might want to trim that off before you write it. Also, you will need to add an Imports System.Text to your code as well.
One note I wanted to add since it can cause some confusion: your loop counter is called RowCount when it is performing the act of counting columns (ColumnCount-1 shows us that). That might cause some confusion down the road and assumptions could be made that might cause coding mistakes.

How to restart a service with VB.NET?

Ok, so I'm new to VB.NET and trying to write a program that prompts the user for a server name and then restarts the IIS on that machine.
Problem 1) namespace System.ServiceProcess is not being recognized.
Problem 2) need help with code, passing servername into sub.
Imports System
Imports System.ServiceProcess
Imports System.IO
Imports System.Threading
Class RestartIIS
Shared Sub Main()
Run()
End Sub
Public Sub Run()
Console.WriteLine("Please enter the Server Name: ")
Dim ServerName As String = Console.ReadLine()
Dim sc As ServiceController = New ServiceController("W3SVC")
sc.Stop()
Thread.Sleep(2000)
sc.Start()
Console.Write("Press Enter to Exit")
Console.ReadLine()
End Sub
End Class
You should add a reference to System.ServiceProcess assembly by right clicking the project and clicking Add Reference... and get command line arguments passed to the Main method like this:
Imports System
Imports System.ServiceProcess
Imports System.IO
Imports System.Threading
Class RestartIIS
Shared Sub Main(ByVal commandLineArgs() as String)
Run(commandLineArgs(0))
End Sub
Public Sub Run(ByVal machineName as String)
Console.WriteLine("Please enter the Server Name: ")
Dim ServerName As String = Console.ReadLine()
Dim sc As ServiceController = New ServiceController("W3SVC", machineName)
sc.Stop()
Thread.Sleep(2000)
sc.Start()
Console.Write("Press Enter to Exit")
Console.ReadLine()
End Sub
End Class
ServiceControl.Stop()
Do
ServiceControl.Refresh()
If ServiceControl.Status = ServiceControllerStatus.Stopped Then
ServiceControl.Start()
Exit Do
End If
Loop