2 Replies - 747 Views - Last Post: 23 January 2011 - 06:34 AM Rate Topic: -----

#1 newsledder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-November 09

String.Format() Help

Posted 23 January 2011 - 02:09 AM

I am sure some of you have seen this project before. I need to create an application that queries customer name (first and last) and there addresses. I need more than that but once I figure what i am doing wrong with that, I should be able to figure out the rest on my own. I am using VS 2010.

I can not figure out the proper syntax for String.Format. I can only get it to display the first and last names of the customers. This is the code I have so far:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim database As New CustomersDataContext()

        Dim displayCustomers =
            From customer In database.Customers
            Order By customer.LastName, customer.FirstName
            Select Name = customer.FirstName & " " & customer.LastName,
                Caddress =
                    From address In customer.CustomerAddresses
                    Order By address.Address.StateProvince
                    Select address.Address.StateProvince


        OutputTextBox1.AppendText("Customers and Customer Addresses")

        For Each customer In displayCustomers
            OutputTextBox1.AppendText(
                String.Format("{0}{1}{2}:", vbCrLf, vbTab, customer.Name))

            For Each address In customer.Caddress
                OutputTextBox1.AppendText(
                String.Format("{0}{1}"), vbCrLf, vbTab, customer.Caddress))
            Next
        Next

    End Sub
End Class



Any help would be great. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: String.Format() Help

#2 newsledder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-November 09

Re: String.Format() Help

Posted 23 January 2011 - 04:48 AM

Ok i am kinda figuring out the String.Format syntax.

I am not sure if that is what my problem is here though. this is my new code....just playing around with the syntax.


Dim database As New CustomersDataContext()

        Dim displayCustomers =
            From customer In database.Customers
            Order By customer.LastName, customer.FirstName
            Select Name = customer.FirstName & " " & customer.LastName,
                address =
                    From address In customer.CustomerAddresses
                    Order By address.Address.AddressLine1
                    Order By address.Address.AddressLine2
                    Order By address.Address.City
                    Order By address.Address.StateProvince
                    Order By address.Address.CountryRegion
                    Select address.Address.AddressLine1, address.Address.AddressLine2,
                    address.Address.City, address.Address.StateProvince, address.Address.CountryRegion
                    Take 10

        OutputTextBox1.AppendText("Customers and Customer Addresses")

        For Each customer In displayCustomers
            OutputTextBox1.AppendText(
                String.Format("{0}{1}{2}{3}:", vbCrLf, vbCrLf, vbTab, customer.Name))

            For Each address In customer.address
                OutputTextBox1.AppendText(
                String.Format("{0}{0}{1}{2}{0}{1}", vbCrLf, vbTab, address))
            Next
        Next



How do I put in vbcrlf's inbetween each item within "address"???

should look like this:



Michael Douglas:
                12345 wysteria Lane
                Anchorage, AK USA



Also I want it to only display the first 10 results. I understand Take (10), but it is not working for me.
Was This Post Helpful? 0
  • +
  • -

#3 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: String.Format() Help

Posted 23 January 2011 - 06:34 AM

Hi,

You can try this;

Select address.Address.AddressLine1, address.Address.AddressLine2, _  
  Environment.Newline, address.Address.City, address.Address.StateProvince, address.Address.CountryRegion  

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1