VB Script to accept PC names in text file and get registry key value out of those systems

Hi All,
My task: Create VB script to accept PC names from a text file, process each host name to get Registry key value of individual host name and finally export them to a text file or an excel sheet having registry key value against each pc.
I want to pull key value of LSFORCEHOST located in HKCU/Environment of each PC and export this value against each pc in a text or Excel file.
What I achieved: I am able to process against single pc name but failed to process 3000+ systems listed in a text file which I tried to process through VB script. I am not pro and learning the VBS and cant write complex code.
My VBS code written so far(It failed many time with issue):
 Option Explicit
 Const HKEY_CURRENT_USER = &H80000001
 Dim oFSO, sFile, oFile, sText, strComputer,oReg, strKeyPath, strValueName, strValue, objFSO, objFile, strContents
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 sFile = "test.txt"
 If oFSO.FileExists(sFile) Then
  Set oFile = oFSO.OpenTextFile(sFile, 1)
   Do While Not oFile.AtEndOfStream
    sText = oFile.ReadLine
     If Trim(sText) <> "" Then
strComputer = sText
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
strKeyPath = "Environment"
strValueName = "LSFORCEHOST"
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\destination.txt",1, ForReading)
strContents = strValue
Set objFile = objFSO.OpenTextFile("C:\destination.txt",2, ForWriting)
objFile.Write strContents
objFile.Close
End If
Loop
oFile.Close
End If
I think when I tried to process each PC name from text file against registry key value, above code not working. As per my knowledge some issue in loop. Do I need to add FOR EACH feature? 
Please help to correct it. Thanks in advance.

I think when I tried to process each PC name from text file against registry key value, above code not working. As per my knowledge some issue in loop. Do I need to add FOR EACH feature? 
Please help to correct it. Thanks in advance.
Your code contains numerous errors. Furthermore you make things difficult for yourself by giving similar names to the objects used for your input and output. If you are a systems administrator then your best bet is to make an effort to learn the language
instead of grabbing a few code fragments from here and there and hoping that somehow they will work.
Try the cleaned up code below for this particular project. Note the consistent code indentation. It helps you enormously when trying to understand the structure of the code. Remember also that you must fully qualify all file paths. Writing to "Destination.txt"
will cause endless confusion because you never know for sure where this file will reside.
 Const HKEY_CURRENT_USER = &H80000001
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 sKeyPath = "Environment"
 sValueName = "LSFORCEHOST"
 sFile = "D:\Test.txt"
 If oFSO.FileExists(sFile) Then
   Set oInput = oFSO.OpenTextFile(sFile, 1)
   Do While Not oInput.AtEndOfStream
     sComputer = oInput.ReadLine
     If Trim(sComputer) <> "" Then
       Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
         & sComputer & "\root\default:StdRegProv")
       oReg.GetStringValue HKEY_CURRENT_USER,sKeyPath,sValueName,sValue
       Set oOutput = oFSO.OpenTextFile("D:\destination.txt",8, True)
       oOutput.WriteLine sValue
       oOutput.Close
    End If
  Loop
  oInput.Close
End If

Similar Messages

  • Shell scripts to read data from a text file and to load it into a table

    Hi All,
    I have a text file consisting of rows and columns as follows,
    GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001
    GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001
    GEF001 000093625 MKL005675 000001 000000 000000 000000 000000 000000 000001 My requirement is that, i should read the first 3 columns of this file using a shell script and then i have to insert the data into a table consisting of 3 rows in oracle .
    the whole application is deployed in unix and that text file comes from mainframe. am working in the unix side of the application and i cant access the data directly from the mainframe. so am required to write a script which reads the data from text file which is placed in certain location and i have to load it to oracle database.
    so I can't use SQL * loader.
    Please help me something with this...
    Thanks in advance.

    1. Create a dictionary object in Oracle and assign it to the folder where your file resides
    2. Write a little procedure which opens the file in the newly created directory object using ULT_FILE and inside the FOR LOOP and do INSERTs to table you want
    3. Create a shell script and call that procedure
    You can use the post in my Blog for such issues
    [Using Oracle UTL_FILE, UTL_SMTP packages and Linux Shell Scripting and Cron utility together|http://kamranagayev.wordpress.com/2009/02/23/using-oracle-utl_file-utl_smtp-packages-and-linux-shell-scripting-and-cron-utility-together-2/]
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • Powershell script for pinging computers from a text file and displaying output with ip address

    i am currently using the following script to display the computers that are pinging, i also want the script to display the
    ipaddress along with the results but the results are displayed not properly, i want the result to be displayed in a table or list format, what am i missing?
    $ServerName = Get-Content "C:\scripts\computers.txt"
    foreach ($Server in $ServerName) {
    if (test-Connection -ComputerName $Server -Count 2 -Quiet) {
    "$Server is Pinging "
    } else
    {"$Server not pinging"
    foreach ($server in $servername) {
    Get-WmiObject -class "Win32_NetworkAdapterConfiguration"|Select-Object IPAddress|Format-List

    Not sure I completely understand your question but looking at the code you posted I see one fairly simple change that may be what you are missing...your Get-WMIObject statement never passes a server name to the command.  You loop through the list
    you obtained but never actually pass that to anything.  So the simple change would be to just do the following...
    foreach($server in $servername)
    Get-WMIObject -class win32_NetworkAdapterConfiguration -computername $server
    | select IPAddress | FT -auto
    you could also tuck that command into the previous foreach/if/else statement and just do each one that actually responds. 

  • Powershell script - how to read a registry hive and store the value in text file and then again read the text file to write the values back in registry

    Hi All,
    powershell script Method required to read a value from registry and then taking the backup of that values in some text file.
    For example the hive is
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path
    and under path i need to take back up  of values in some text file and then put some value in the registry after back is taken in text file.
    Also how to read the text file values so that we can again write to registry hive  back from the back up text file.
    Your help is much appreciated.
    Umeed4u

    I think you need to read this first:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)

  • Reading a text file and putting it in a textarea

    hi can u tell me how to read a text file and display the contents in a text area using jsp please?
    thanks :o)

    <%@ page import="java.sql.*, java.io.*" %>
    <HTML>
    <HEAD>
         <TITLE>User Application Area</TITLE>
    <SCRIPT LANGUAGE="javascript" SRC="cal2.js">
    </SCRIPT>
    <SCRIPT LANGUAGE="javascript" SRC="cal_conf2.js"></SCRIPT>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <%
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:fypproject","","");
    Statement st = con.createStatement();
    String email = (String)session.getAttribute("email");
    String levelStatus = (String)session.getAttribute("levelStatus");
    String details = "SELECT PD.Forename, PD.Surname, L.Level_Name FROM Personal_Details PD,
    Login_Details LD, Levels L WHERE PD.Email_Address = '" + email + "' AND PD.Email_Address =
    LD.Email_Address AND LD.Level_ID = '" + levelStatus + "' AND LD.Level_ID = L.Level_ID";
    ResultSet rsDet = st.executeQuery(details);
    if(rsDet.next()) {
    String forename = rsDet.getString("Forename");
    String surname = rsDet.getString("Surname");
    String levelName = rsDet.getString("Level_Name");
    %>
    <DIV ALIGN="center"><H1>User Application Arena</H1></DIV>
    <BR>
    <H4>Welcome back <% out.println(forename + " " + surname); %> </H4>
    <BR>
    Your status is:
    <FONT COLOR = "red">
    <% out.println(levelName); %>
    </FONT>
    <BR>
    <%
    if(levelStatus.compareTo("0")==0) {
    %>
    <BR>
    <DIV ALIGN="center">
    Please come back later and re-check your status to see if your application has progressed. If it has
    been more than a week since you submitted it please phone the HR department on 020 7123 4567
    <BR><BR>
    Log Out
    </DIV>
    </FORM>
    <%
    else if(levelStatus.compareTo("1")==0) {
    %>
    <FORM NAME="sampleform" ACTION="ProcessInterview.jsp">
    <DIV ALIGN="center">
    Congratulations, we would like to invite you for a First Round tests and interview. Please select a
    date that would suit you on our online calendar below
    <BR><BR>
    <SMALL>PLEASE CLICK HERE TO SELECT A DATE</SMALL>
    <BR><BR>
    <INPUT TYPE="text" NAME="firstinput" SIZE=20>
    <BR><BR>
    <INPUT TYPE="submit" VALUE="Confirm">
    </DIV>
    </FORM>
    <%
    else if(levelStatus.compareTo("2")==0) {
    %>
    <FORM NAME="sampleform" ACTION="ProcessInterview.jsp">
    <DIV ALIGN="center">
    Congratulations, we would like to invite you for a Second Round interview. Please select a date that
    would suit you on our online calendar below
    <BR><BR>
    <SMALL>PLEASE CLICK HERE TO SELECT A DATE</SMALL>
    <BR><BR>
    <INPUT TYPE="text" NAME="firstinput" SIZE=20>
    <BR><BR>
    <INPUT TYPE="submit" VALUE="Confirm">
    </DIV>
    </FORM>
    <%
    else if(levelStatus.compareTo("3")==0) {
    File inFile = new File("offer.txt");
    StringBuffer sb = new StringBuffer();
    BufferedReader buf = new BufferedReader(new FileReader(inFile));
    while (buf.ready()) {       
    sb.append(buf.readLine());
    buf.close();
    %>
    <TEXTAREA NAME ="text" ROWS="10" COLS="60">
    <%= sb.toString() %>
    </TEXTAREA>
    <%
    else if(levelStatus.compareTo("4")==0) {
    out.println("send rej email");
    st.close();
    con.close();
    %>
    </BODY>
    </HTML>
    THANKS!! :o)

  • Include text file and display from text file

    Ok. I'm found the site with the monkey on the the flash thing and all it shows is a name, email and something else and I used it and it works by including a txt file and displaying text from that file as putting down this information
    name.text = this.name;
    and I can't find the site anymore to get help.
    I want to know how to include a PHP script that shows this information like this
    text=something I need&username=My Name&email=[email protected]
    I want to show this stuff on the flash but every time I execute by using it as localhost/test.php, it will show a sentax error.
    This is really stressing me out and I need a lot of help on this stuff.
    Can someone help me?

    ok. let me describe something else.
    there's 3 text boxes that is dynamic text.
    one of them is called name
    the other one is called email
    and last one is called location
    in the text file, it shows this for importing to the flash file
    name=My Name&email=EMAIL&location=My Location
    When viewing the flash file that you created, it shows the name, it shows the email, and it shows location.
    When I do it on my own even with a text file, it keeps on saying that there is an error on line 1.
    I found a site that shows how to do it and it shows what to put in a text file, and it shows the action script. On the FLA file that he shows me has a monkey on the flash file and it has 3 text boxes that I described above. As well as the text file, it is the same. I used the example and it worked but I can't find the example again. I don't know what happened to the website and I don't know what happened to the download I had but it is not downloaded any more. I have adanced systemcare pro so it clears out my recent web searches and my recent downloads so I can't find it. I did a google search on anything about action scripts. I even did a monkey action script search and I couldn't find it.
    It's making me mad and I don't know what to do. This is stressing me out way more than you think.
    UPDATE:
    I did a google search on a file I found in my www folder and I found it. finally.
    Here's the site.
    http://www.kirupa.com/developer/mx/externaldata.htm
    now, I need to figure out how to load it from a PHP file.

  • How to read the contents of a text file and populate the data in a table ?

    Hello All,
      Can anyone advise on how to acheieve the above ? I am trying to read in a text file (CSV) and have the contents populated to the respective UI elements in a table. Any help is greatly appreciated.
    from
    Kwok Wei

    Hi,
    Let us consider you have list of names(Seperated by delimeter) in a text file and you want to display in  a table.
    1. Create Context Node "Names" and context attribute "Name"
    2. Create Table and bind to the above context.
    3.Write the following code in the "Init method.
    try{
    FileReader f =new FileReader("");
    BufferedReader r=new BufferedReader(f);
    String names=r.readLine();
    Vector Names=new Vector();
    // Use Tokenizer and store all the names i a vector//
    for(int i=0;i<Names.size();i++){
    IPrivate<<VieName>>.INameElement ele=wdContext.createNameElement();
    ele.set<<Name>>( Names.get(i).toString());
    wdContext.NodeName().addElement(ele);
    Regards, Anilkumar
    Message was edited by: Anilkumar Vippagunta

  • How can i read the text files and buffer the data in Vector?

    hi. I have been running into this problem for days, but with no luck and losing right direction.
    The problem is : I am trying to read a text file and buffer the data into a
    Queue for each user.
    the sample text file is as below:( 1st column is timestamp, 2nd is user_id, 3rd is packet_id, 4th is packet_seqno, 5th is packet_size)
    0 1 1 1 512
    1 2 1 2 512
    2 3 1 3 512
    3 4 1 4 512
    4 5 1 5 512
    5 6 1 6 512
    6 7 1 7 512
    7 8 1 8 512
    8 9 1 9 512
    9 10 1 10 512
    10 1 2 11 512
    11 2 2 12 512
    12 3 2 13 512
    13 4 2 14 512
    14 5 2 15 512
    15 6 2 16 512
    16 7 2 17 512
    17 8 2 18 512
    18 9 2 19 512
    19 10 2 20 512
    20 1 3 21 512
    21 2 3 22 512
    22 3 3 23 512
    23 4 3 24 512
    24 5 3 25 512
    25 6 3 26 512
    26 7 3 27 512
    27 8 3 28 512
    28 9 3 29 512
    29 10 3 30 512
    30 1 4 31 512
    31 2 4 32 512
    32 3 4 33 512
    33 4 4 34 512
    34 5 4 35 512
    35 6 4 36 512
    36 7 4 37 512
    37 8 4 38 512
    38 9 4 39 512
    39 10 4 40 512
    40 1 5 41 512
    41 2 5 42 512
    42 3 5 43 512
    43 4 5 44 512
    44 5 5 45 512
    45 6 5 46 512
    46 7 5 47 512
    47 8 5 48 512
    48 9 5 49 512
    49 10 5 50 512
    50 1 6 51 512
    51 2 6 52 512
    52 3 6 53 512
    53 4 6 54 512
    54 5 6 55 512
    55 6 6 56 512
    56 7 6 57 512
    57 8 6 58 512
    58 9 6 59 512
    59 10 6 60 512
    60 1 7 61 512
    61 2 7 62 512
    62 3 7 63 512
    63 4 7 64 512
    64 5 7 65 512
    65 6 7 66 512
    66 7 7 67 512
    67 8 7 68 512
    68 9 7 69 512
    69 10 7 70 512
    70 1 8 71 512
    71 2 8 72 512
    What I wanna do is to read all the data above and buffer them in a queue for each user( there are only 10 users in total).
    I already created a class called Class packet:
    public class packet {
        private int timestamp;
        private int user_id;
        private int packet_id;
        private int packet_seqno;
        private int packet_size;
        /** Creates a new instance of packet */
        public packet(int timestamp,int user_id, int packet_id,int packet_seqno, int packet_size)
            this.timestamp = timestamp;
            this.user_id=user_id;
            this.packet_id=packet_id;
            this.packet_seqno=packet_seqno;
            this.packet_size=packet_size;
    }then I wanna to create another Class called Class user which I can create a queue for each user (10 users in total) to store type packet information. the queue for each user will be in the order by timestamp.
    any idea and sample code will be appreciated.

    Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
    Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave.

  • Having trouble reading specific lines from a text file and displaying them in a listbox

    I am trying to read specific lines from all of the text files in a folder that are reports. When I run the application I get the information from the first text file and then it returns this error: "A first chance exception of type 'System.ArgumentOutOfRangeException'
    occurred in mscorlib.dll"
    Below is the code from that form. 
    Option Strict On
    Option Infer Off
    Option Explicit On
    Public Class frmInventoryReport
    Public Function ReadLine(ByVal lineNumber As Integer, ByVal lines As List(Of String)) As String
    Dim intTemp As Integer
    intTemp = lineNumber
    Return lines(lineNumber - 1)
    lineNumber = intTemp
    End Function
    Public Function FileMatches(ByVal folderPath As String, ByVal filePattern As String, ByVal phrase As String) As Boolean
    For Each fileName As String In IO.Directory.GetFiles(folderPath, filePattern)
    If fileName.ToLower().Contains(phrase.ToLower()) Then
    Return True
    End If
    Next
    Return False
    End Function
    Private Sub frmInventoryReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim intcase As Integer = 1
    Dim strTemp, strlist, strFile As String
    Dim blnCheck As Boolean = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Do While blnCheck = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Dim objReader As New System.IO.StreamReader("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\" & strFile)
    Dim allLines As List(Of String) = New List(Of String)
    Do While objReader.Peek <> -1
    allLines.Add(objReader.ReadLine())
    Loop
    objReader.Close()
    strlist = ReadLine(1, allLines) & "" & ReadLine(23, allLines)
    lstInventory.Items.Add(strlist)
    intcase += 1
    strTemp = intcase.ToString
    strFile = "Report Q" & intcase.ToString & ".txt"
    blnCheck = FileMatches("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\", "*.txt", intcase.ToString)
    Loop
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim intcase As Integer = 1
    Dim strTemp, strlist, strFile As String
    Dim blnCheck As Boolean = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Do While blnCheck = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Dim objReader As New System.IO.StreamReader("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\" & strFile)
    Dim allLines As List(Of String) = New List(Of String)
    Do While objReader.Peek <> -1
    allLines.Add(objReader.ReadLine())
    Loop
    objReader.Close()
    strlist = ReadLine(1, allLines) & "" & ReadLine(23, allLines)
    lstInventory.Items.Add(strlist)
    intcase += 1
    strTemp = intcase.ToString
    strFile = "Report Q" & intcase.ToString & ".txt"
    blnCheck = FileMatches("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\", "*.txt", intcase.ToString)
    Loop
    End Sub
    End Class
    Sorry I'm just beginning coding and I'm still a noob. Any help is appreciated. Thank you!

    Ok, so if I'm following this correctly you should be able to just loop through all of the files in that folder whose file name matches the pattern and then read the first 22 lines, recording only the first and the last.
    Exactly how you store the animal data probably depends on how you are going to display it and what else you are going to do with it.  Is there anything other than name and cage number that should be associated with each animal?
    You might want to make a dataset with a datatable to describe the animal, or you might write a class, or you might just use something generic like a Tuple.  Here's a simple class example:
    Public Class Animal
    Public Property Name As String
    Public Property Cage As String
    Public Overrides Function ToString() As String
    Return String.Format("{0} - {1}", Name, Cage)
    End Function
    End Class
    With that you can use a routine like the following to loop through all of the files and read each one:
    Dim animals As New List(Of Animal)
    Dim folderPath As String = "E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\"
    For Each filePath As String In System.IO.Directory.GetFiles(folderPath, "Report Q?.txt")
    Using reader As New System.IO.StreamReader(filePath)
    Dim lineIndex As Integer = 0
    Dim currentAnimal As New Animal
    While Not reader.EndOfStream
    Dim line As String = reader.ReadLine
    If lineIndex = 0 Then
    currentAnimal.Name = line
    ElseIf lineIndex = 22 Then
    currentAnimal.Cage = line
    Exit While
    End If
    lineIndex += 1
    End While
    animals.Add(currentAnimal)
    End Using
    Next
    'do something to display the animals list
    Then you might bind the animals list to a ListBox, or loop through the list and populate a ListView.  If you decided to fill a datatable instead of making Animal instances, then you might bind the resulting table to a DataGridView.
    There are lots of options depending on what you want and what all you need to do.
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Where does this java program read a text file and how does it output the re

    someone sent this to me. its a generic translator where it reads a hashmap text file which has the replacement vocabulary etc... and then reads another text file that has what you want translated and then outputs translation. what i don't understand is where i need to plugin the name of the text files and what is the very first line of code?
    [code
    package forums;
    //references:
    //http://forums.techguy.org/development/570048-need-write-java-program-convert.html
    //http://www.wellho.net/resources/ex.php4?item=j714/Hmap.java
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class Translate {
    public static void main(String [] args) throws IOException {
    if (args.length != 2) {
    System.err.println("usage: Translate wordmapfile textfile");
    System.exit(1);
    try {
    HashMap words = ReadHashMapFromFile(args[0]);
    System.out.println(ProcessFile(words, args[1]));
    } catch (Exception e) {
    e.printStackTrace();
    // static helper methods
    * Reads a file into a HashMap. The file should contain lines of the format
    * "key\tvalue\n"
    * @returns a hashmap of the given file
    @SuppressWarnings("unchecked")
    private static HashMap ReadHashMapFromFile(String filename) throws FileNotFoundException, IOException {
    BufferedReader in = null;
    HashMap map = null;
    try {
    in = new BufferedReader(new FileReader(filename));
    String line;
    map = new HashMap();
    while ((line = in.readLine()) != null) {
    String[] fields = line.split("\\t", 2);
    if (fields.length != 2) continue; //just ignore "invalid" lines
    map.put(fields[0], fields[1]);
    } finally {
    if(in!=null) in.close(); //may throw IOException
    return(map); //returning a reference to local variable is safe in java (unlike C/C++)
    * Process the given file
    * @returns String contains the whole file.
    private static String ProcessFile(Map words, String filename) throws FileNotFoundException, IOException {
    BufferedReader in = null;
    StringBuffer out = null;
    try {
    in = new BufferedReader(new FileReader(filename));
    out = new StringBuffer();
    String line = null;
    while( (line=in.readLine()) != null ) {
    out.append(SearchAndReplaceWordsInText(words, line)+"\n");
    } finally {
    if(in!=null) in.close(); //may throw IOException
    return out.toString();
    * Replaces all occurrences in text of each key in words with it's value.
    * @returns String
    private static String SearchAndReplaceWordsInText(Map words, String text) {
    Iterator it = words.keySet().iterator();
    while( it.hasNext() ) {
    String key = (String)it.next();
    text = text.replaceAll("\\b"+key+"\\b", (String)words.get(key));
    return text;
    * @returns: s with the first letter capitalized
    String capitalize(String s)
    return s.substring(0,0).toUpperCase() + s.substring(1);
    }

    without what arguments?Without any arguments. If there are no arguments, there are no arguments of any kind. If you have a zoo with no animals in it, it's not meaningful to ask whether the animals which are not there are zebras or elephants.
    does it prompt me to give it a text file name?Apparently.
    when i run it this is all i get:
    usage: Translate wordmapfile textfile
    Press any key to continue...Right. And "wordmapfile" is almost certainly supposed to be a file that holds the word map, and "textfile" is almost certainly the file of text that it's going to translate.

  • Searching a text file and printing the line if found!

    Hi, Im fairly new to JAVA and have been googling this for hours and havent found any results that
    have helped me...
    Im looking to search a text file for a value that is in a that is delimited by colons
    eg 45787 : 398948 : 398884 : 398984
    IF that value is found I need to print this entire line and move it into a string.
    I can work out the delimit part, the problem for me is a)searching the text file
    and b) tell java to print that line only??
    Any help would be very very much appreciated
    Cheers
    James

      public void printCourses() throws Exception
                stuinput[] courseObjArray = new stuinput[10]; //Make sure this is the same as the ammount in the text
                   Scanner sc = new Scanner(new File("testfile.txt"));
                   int i=0;
                   boolean found = false;
                   while(sc.hasNextLine())
                   //Delimit this line with scanner
                   Scanner sc1 = new Scanner(sc.nextLine());
                   sc1.useDelimiter(":");
                   courseObjArray[i] = new stuinput(sc1.next(),sc1.next());
                   i++;
                   }//while
                   for(int i1 = 0;i1 < courseObjArray.length;i1++)
                   System.out.println(courseObjArray[i1].courseCode);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println("-----------------");     
                   String courseCode2 = "courseObjArray[i1].courseCode";
                   if (courseCode2  == "12345")
                        System.out.println("working");
                   else{System.out.println("Not Found");}
           }hmmm just wondering why could this method always return a "Not Found"....if the text file had a whole bunch of values like this
    12345:Course1
    12344:Course2
    12343:Course3
    isnt it surposed to return 1 "Working"?? because there is a 12345 in on of the line, in the semi colon delimited line with 2 values, one being the course code, one being the course name??
    Given that there is 10 lines (from Array Object)

  • Compare data from 2 text files and output match

    Hi all,
    I need some advice.
    Firstly in BinaryCode.txt the data is as such:
    Replace BinaryCode0 1 0 0 0 0 0 0 0 0
    Replace BinaryCode0 1 0 0 0 0 0 0 0 1
    Replace BinaryCode1 1 1 1 0 1 1 1 1 1
    Replace BinaryCode1 1 0 0 0 0 0 0 0 0
    the first line in the text file is the header. So I need to check if the names in the second column (BinaryCode0 or BinaryCode1)appear in the Timed_Sets.txt file.
    The data in Timed_Sets.txt is as such:
    BinaryCode0,6,40,.........................
    BinaryCode0,7,40,.........................
    BCName1,0,20,.............................
    BCName1,1,20,............................. 
    For example since  BinaryCode0 is a match I will output the entire row in Timed_Set.txt to another array. 
    I have been working on a program but I don't get the expected output. 
    The text files and the VI are attached.
    I appreciate your kind assistance in the matter.
    Thank You
    Regards
    kart 
    Solved!
    Go to Solution.
    Attachments:
    BinaryCode.txt ‏1 KB
    compare text files.vi ‏15 KB
    Timed_Sets.txt ‏2 KB

    If I understood correctly what the output should be then what you basically need to do is to walk through the column in BinaryCode.txt and for each unique value pull out the corresponding rows from Timed_Sets.txt. There's a variety of ways to do this, depending on how much data you have and whether or not you can use any kind of prior knowledge as to the actual file content (such as the names of the keys being searched). Attached is one way. Modify as needed.
    Attachments:
    compare text files MOD.vi ‏27 KB

  • Pool data from text file and insert into database

    Can anyone tell me how to pool data from a text file and insert into database?
    let's say my text file is in this format
    123456 Peter 22
    234567 Nicholas 24
    345678 Jane 20
    Then I need to insert the all the value for this three column into a table which has the three column name ID, Name, Age
    Anyone knows? I need to do this urgently...Thank in advanced

    1. Use BufferedReader and read the file line by line.
    2. Loop thru the file and do the following steps with in this loop.
    3. Use StringTokenizer to seperate each line into three values (columns).
    4. Now create a insert statement with these values and add the statement to the batch (using addBatch() method of PreparedStatement or Statement).
    5. Finally (after exiting the loop), execute these batch of statements (using ps.executeBatch()).
    Sudha

  • How can FMS create a text file and write data into it in the Server application folders?

    Recently, I writed a programe about creating a text file and writing data into it in the server application folder. My code is as following:
               var fileObj = new File("/MyApp/test.txt");
               if( fileObj !=  null)
                      if(fileObj.open( "text", "append"))
                            fileObj.write( "                                                      ———— Chat Info Backup ————\r\n" );
                            fileObj.close( );
                            trace("Chat info backup document :" +  fileObj.name + " has been created successfully!");    
    But when I run it, FMS throw the error as following: File operation open failed  ;  TypeError: fileObj has no properties.
    Can you help me ? Thanks in advance.
    Supplement: The text file named test.txt doesn't exist before create the fileObj, an instance of File Class.

    Is MyApp the name of the application directory, or is it a child of the application directory? If myApp is the app name, just use test.txt as the path flag in the file constructor.

  • Help needed regarding reading in a text file and tokenizing strings.

    Hello, I require help with a task I've been set, which asks me to read in a text file, and check the contents for errors. The text file contains lines as follows.
    surname:forename:1234:01-02-06
    I can read in the file, but dont know how to split the strings so each token can be tested (ie numbers in the name tokens)
    However, I am not allowed to use regex functions, only those found in java.io.*
    I think i should be putting the tokens into an array, but have had no luck so far in doing so. Any help would be appreciated.

    public class Validator {
         public static void main(String args[]) {
              String string = "Suname:Forename:1234:01_02-06";
              String stringArray[] = string.split(":");
              System.out.println (validateLetters(stringArray[0]));//returns true
              System.out.println (validateNumbers(stringArray[3]));//returns false
         static boolean validateLetters(String s) {
                 for(int i = 0; i < s.length(); i++) {
                 char c = s.charAt(i);
                 if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z')) {
                         return false; //return false if one of characters is other than a-z A-Z
                 }//end if
                 }//end for
                 return true;
         }//end validateLetters
         static boolean validateNumbers(String s) {
                 for(int i = 0; i < s.length(); i++) {
                 char c = s.charAt(i);
                 if ((c < '0' || c > '9') && (c != '-')) {
                         return false; //return false if one of characters is other than 0-9 or -
                 }//end if
                 }//end for
                 return true;
         }//end validateNumbers
    }

Maybe you are looking for